su from normal user in scripts

Discussion in 'Programming/Scripts' started by jack777, Apr 25, 2008.

  1. jack777

    jack777 New Member

    Got a cron to run everyday under my user. this cronjob runs a script from my /home/jack/scripts/

    #   su to root and run a script, return with result
    #   su -
    #   passwd
    #   run /
    #   return with result 
    #   the result will copy 2 files from /prod/app/logs/ and throws to my /home/jack/scripts/file1.txt and file2.txt
    awk -F" "  '$5==0 && $3=="ServerA"{print $1}'  file1.txt file2.txt | sort -r | head -1 > output.txt
    uuencode output.txt output.txt | mailx -s "Todays Server ErrorLog Reprot" [email protected]
    I am having the root password. Need to know how to su from normal user, run script which has root privileges, logout from user with result to my user and continue the next sequence of my script.

    All the above steps inside # remark statements needs proper code.

    Thanks in advance
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    Have a look at the sudo command instead of su and the sudoers file. It allows you to execute a program or script under different priveliges.

Share This Page