Generate script in bash and save it to location requiring sudo

后端 未结 3 1811
孤街浪徒
孤街浪徒 2021-02-02 08:23

In bash I can create a script with a here-doc like so as per this site: http://tldp.org/LDP/abs/html/abs-guide.html#GENERATESCRIPT

(
cat <<\'EOF\'
#!/bin         


        
3条回答
  •  情歌与酒
    2021-02-02 09:03

    Non of the answers expanded environment variables. My workaround is a tmp file and a sudo mv.

    l_log=/var/log/server/server.log
    l_logrotateconf=/etc/logrotate.d/server
    tmp=/tmp/$$.eof
    cat << EOF > $tmp
    $l_log {
       rotate 12
       monthly
       compress
       missingok
       notifempty
    }
    EOF
    sudo mv $tmp $logrotateconf
    

提交回复
热议问题