Operating System - HP-UX
1833030 Members
3031 Online
110049 Solutions
New Discussion

how to include commands after calling nohup in ksh script

 
apple
Super Advisor

how to include commands after calling nohup in ksh script

dear hpux gurus,
i would like to remove thousand of directories inside this folder. i created ksh script.how to execute the command using nohup. currently i'm using like this:
# ./script &
whenever i exit the session, it will exit this session too. hope to hear from you. thank you.
should u have any comments to my script or anything, would appreciate your advice. thank you


# more script
#!/usr/bin/ksh
cd /restore_01/20080620old/item1/data
rm -R 990
rm -R 987
rm -R 986
rm -R 985
rm -R 984
rm -R 983
5 REPLIES 5
Vijaya Kumar_3
Respected Contributor

Re: how to include commands after calling nohup in ksh script

In your case, one way of executing this would be:

nohup ./script &

This will run the script in background and immune to logout/exits.

Regards
Vijay Chinnasamy
Known is a drop, unknown is ocean - visit me at http://vijay.theunixplace.com
Vijaya Kumar_3
Respected Contributor

Re: how to include commands after calling nohup in ksh script

Regarding your command script, you may want to use the -f switch for rm command. Please be cautious though. Along with -R, you cane use it like this "-Rf". f - forcibly remove. Please be cautios using this option (For example, make sure you are not in root folder etc). Also, to improve a script little bit, you may want to check the exit status of the cd command first, and then run the rm command... Something like this:

cd /restore_01/20080620old/item1/data

if [[ $? -eq 0 ]]
then
rm -Rf 990
else
exit 1
fi

Known is a drop, unknown is ocean - visit me at http://vijay.theunixplace.com
Kenan Erdey
Honored Contributor

Re: how to include commands after calling nohup in ksh script

hi,

except nohup you can use (./script & ). this opens a sub shell and puts it to background.

Kenan.
Computers have lots of memory but no imagination
Suraj K Sankari
Honored Contributor

Re: how to include commands after calling nohup in ksh script

Hi,

I think you can use like this

# nohup script &

Suraj

Dennis Handly
Acclaimed Contributor

Re: how to include commands after calling nohup in ksh script

You could also optimize your rm command to:
rm -rf 990 987 986 985 984 983 ...