Creating a file with iocage?

Daisuke

Contributor
Joined
Jun 23, 2011
Messages
1,041
I'm trying to automate a jail creation with a script, I cannot create the file remotely:

Code:
root@nas[~]# cat > /mnt/services/iocage/jails/plexmediaserver/root/usr/local/etc/nginx/nginx.conf << 'EOF'
worker_processes         auto;

events {
    multi_accept         on;
    worker_connections   1024;
}

http {
    server {
        listen           80 default_server;
        server_name      _;
        access_log       off;
        index            index.html;
        root             /usr/local/www/nginx;

        proxy_buffering  off;
        proxy_redirect   off;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;

        location / {
            proxy_pass   http://localhost:32400;
        }
    }
    include              mime.types;
}
'EOF'
heredoc>


In a normal FreeBSD environment, the file will be created. Not in TrueNAS 12, I get the heredoc> prompt. What would be the correct cat or iocage exec plexmediaserver command format to create a file with delimiter content?
 
Last edited:

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
Try removing the single quotes from the closing 'EOF'.
 

colmconn

Contributor
Joined
Jul 28, 2015
Messages
174
Another way that doesn't involve knowing the path to where the jails are installed:
Code:
cat <<EOF | iocage exec ${JAIL_NAME} -- "cat - > /usr/local/etc/nginx/nginx.conf"
user  www;
worker_processes  auto;

events {
    worker_connections  1024;
}
EOF
 

Patrick M. Hausen

Hall of Famer
Joined
Nov 25, 2013
Messages
7,776
I need the quotes so I escape variables, for example the ones in rc.d init scripts.
On the initial <<'EOF', yes. Not on the closing one.

Code:
$ man sh
[...]
   Here Documents
       This type of redirection instructs the shell to read input from the current source until a line containing only
       word (with no trailing blanks) is seen.  All of the lines read up to that point are then used as  the  standard
       input for a command.

       The format of here-documents is:

              <<[-]word
                      here-document
              delimiter

       No parameter expansion, command substitution, arithmetic expansion, or pathname expansion is performed on word.
       If any characters in word are quoted, the delimiter is the result of quote removal on word, and  the  lines  in
       the  here-document  are  not  expanded.


If any characters in word are quoted, the delimiter is the result of quote removal on word.

That's why your closing 'EOF' is not recognized ...
 
Top