running script @ startup

General support questions
Post Reply
knzzz
Posts: 157
Joined: 2017/02/25 12:41:42

running script @ startup

Post by 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

Post by 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: 157
Joined: 2017/02/25 12:41:42

Re: running script @ startup

Post by 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
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: running script @ startup

Post by TrevorH » 2017/12/28 10:17:58

crontab -e -u thatuser
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

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

Re: running script @ startup

Post by 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: 157
Joined: 2017/02/25 12:41:42

Re: running script @ startup

Post by 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: 739
Joined: 2007/09/07 10:56:28
Location: Finland

Re: running script @ startup

Post by 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: 157
Joined: 2017/02/25 12:41:42

Re: running script @ startup

Post by knzzz » 2018/01/03 08:27:43

Thanks a zillion it worked.

Post Reply