Avatar of The Rock
The Rock
Flag 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
LinuxLinux DistributionsShell Scripting

Avatar of undefined
Last Comment
The Rock

8/22/2022 - Mon
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...
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
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
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
SOLUTION
gheist

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
arnold

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
The Rock

ASKER
Tried all it works on rhel 6 but dont know why it doesnt works while reboot on rhel 7.2 :(
arnold

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?
The Rock

ASKER
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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
omarfarid

If they are both on same filesystem then create hardlink instead of softlink
arnold

The issue might be that /opt is unavailable when you try to run the script?
can you post df -k
ASKER CERTIFIED SOLUTION
skullnobrains

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
The Rock

ASKER
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
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
skullnobrains

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"
The Rock

ASKER
Thanks all for your suggestions. Appreciated