running script @ startup

General support questions
knzzz
Posts: 79
Joined: 2017/02/25 12:41:42

running script @ startup

Postby knzzz » 2017/12/20 05:28:23

Hi Team,

I want to run a script at the time of system reboot

for root user

/etc/rc.local

/path/of/the/script.sh

for non root user

su - test -c "/path-to-shell-script"

could you please suggest the above mentioned methods are correct?

steadyeddyd
Posts: 1
Joined: 2017/12/25 00:07:33

Re: running script @ startup

Postby steadyeddyd » 2017/12/25 00:16:00

That'll work but an easier way would be to use cron and specifying a line with:

@reboot (include other details here to run your command)

Check out the man page for crontab:

man 5 crontab

for lots of nifty time options.

(BTW modify the crontab with

crontab -e

(and you can view it with

crontab -l

))

knzzz
Posts: 79
Joined: 2017/02/25 12:41:42

Re: running script @ startup

Postby knzzz » 2017/12/28 04:36:01

Thanks for your reply but how to apply for my requirement using cron, i need to run only for that particular user @ the time of system startup, also read the man 5 crontab

User avatar
TrevorH
Forum Moderator
Posts: 21723
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: running script @ startup

Postby TrevorH » 2017/12/28 10:17:58

crontab -e -u thatuser
CentOS 5 died in March 2017 - migrate NOW!
Full time Geek, part time moderator. Use the FAQ Luke

knzzz
Posts: 79
Joined: 2017/02/25 12:41:42

Re: running script @ startup

Postby knzzz » 2018/01/03 07:15:40

Hi Thanks for your suggestion i tried

[root@test ~]# crontab -e -u user
@reboot : "/home/user/test.sh"

still it doesnt work any suggestion

Regards
Kanna

knzzz
Posts: 79
Joined: 2017/02/25 12:41:42

Re: running script @ startup

Postby knzzz » 2018/01/03 07:16:49

[root@test ~]# crontab -e -u user
@reboot : "/home/user/test.sh"

still it doesnt work any suggestion

i also tried without double quote

@reboot : /home/user/test.sh

markkuk
Posts: 736
Joined: 2007/09/07 10:56:28
Location: Finland

Re: running script @ startup

Postby markkuk » 2018/01/03 07:24:55

There shouldn't be any colon characters in the crontab file. The line should be:

Code: Select all

@reboot   /home/user/test.sh

Check that the file is actually marked executable (chmod +x /home/user/test.sh).

knzzz
Posts: 79
Joined: 2017/02/25 12:41:42

Re: running script @ startup

Postby knzzz » 2018/01/03 08:27:43

Thanks a zillion it worked.