Activities

September 2012
M T W T F S S
« Aug   Oct »
 12
3456789
10111213141516
17181920212223
24252627282930

Running a script under user environment on booting.

How do I run a script under a user environment at every time system booted.

Senario : I want to synchronize the files from a remote ftp location each time new instance created through AWS auto scaling. I uses lftp command and using mirror option to sync. the files. Why I’m doing such sync activities is dev. team has to be update/modify the code until the product has free of errors in production move. you may need to add this command in “/etc/rc.local” file.

#/usr/bin/lftp  -f /home/installation/scripts/lftp_params.txt
#cat /home/installation/scripts/lftp_params.txt
open  10.10.10.12
user user1  password
cd /
mirror --exclude uploads/ --exclude-glob application/config/database.php  --exclude-glob *.htaccess  --exclude style/parsed/  --exclude application/cache/ --exclude application/logs/ --exclude js/parsed/  --exclude style/parsed/  --delete --only-newer --exclude captcha/   --verbose  /   /home/user/public_html/
exit

How to run this script under “user” privilege while booting the server.

Here is the command to execute a command under user environment.

Syntax : su username -c ‘command’

For our scenario , it will be,

 su user-c '/usr/bin/lftp  -f /home/installation/scripts/lftp_params.txt'

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>