Link to home
Start Free TrialLog in
Avatar of The Rock
The RockFlag for India

asked on

how to run my script during boot in rhel 7

I have RHEL 7.2 and not able to run my scirpt wile reboot actually when i am creating a soft link of my script then it wont work but if i am creating a file in init.d it works. please help with the correct process in rhel 7.2
Avatar of Member_2_406981
Member_2_406981

Another thing to think of, maybe its a workable solution for your script.

create a cron job that runs once at boot time and execute the script there...
Avatar of The Rock

ASKER

Thanks but have a look at below link if you understand something because i tried but not a sucess with systemd. Might be you have any idea on this:

https://access.redhat.com/articles/754933

thanks
Avatar of omarfarid
make sure that:

- you have SXXscriptname in the right run level dir. Name should start with S and XX is a sequence number. e.g. S88myscript
- all file systems are already mounted
- use full path names for files, folders, commands, etc
- set necessary env. variables
- if you need to run commands with specific username then use us - username command
SOLUTION
Avatar of gheist
gheist
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Tried all it works on rhel 6 but dont know why it doesnt works while reboot on rhel 7.2 :(
What does the item you want to run at bootup supposed to do?
Where are you trying and what is happening.

Are saying you create an init.d script and link it out, but after the first reboot all those parameters are gone?
No I have just create a simple script let say creating a file and directory using touch and mkdir full path of command under init.d . only diffrence is script is located under /opt and softlink is in under init.d

but it wont work.

if i place original file under init.d not a softlink then it works even after reboot
If they are both on same filesystem then create hardlink instead of softlink
The issue might be that /opt is unavailable when you try to run the script?
can you post df -k
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello Skullnobrains,

Thanks your cron @reboot option looks good but i dont know about syntax never used it could you please help it how to do it if my script is /opt/abc.sh how to run it and what entry need to make it ?

thank you
in the regular crontab, something like this should do

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
@reboot sh /opt/abc.sh > /var/log/output.log 2>&1

Open in new window


if you're using a file in cron.d you'd need to add the username in front of @reboot

i added a standard path as crontab use a default path which lacks many commands

have a look at "man 5 crontab"
Thanks all for your suggestions. Appreciated