I am newbie to unix.I am trying to use NOHUP command in shell script it works fine with only "nohup test.sh 10 &" and "/opt/user/nohup test.sh 10 &" gives an error saying "ksh: /opt/user/nohup : not found".
The nohup is the current working directory if given at the command line.
If I use in the shell script it is the home directory of the user ie., /opt/user is the default home dir for the user when he logins in.
I have hardcoded the path and also used as a variable but it still remains the same
# This script calls the weblogic start script if the file exist
if [ -f /opt/user/scripts/test.sh ]
then
echo "testing script"
su - username -c "nohup /opt/user/scripts/test.sh &"
exit $?
fi
#!/bin/ksh
# This script calls the test script if the file exist
if [ -f /opt/user/scripts/test.sh ]
then
HOME="/opt/user"
echo "testing script"
su - username -c "${HOME}/nohup /opt/user/scripts/test.sh &" // Error ksh:/opt/user/nohup:not found
exit $?
fi
Again, please post your OS and version, and the output of the following command:
$ which nohup
This will assist in getting you a answer. Since you seem to insist that /opt/user/nohup is a file on your server, please also post the output of these commands:
$ file /opt/user/nohup
$ ls -l /opt/user/nohup
I have reason to believe you are incorrect in using ${HOME}/nohup in the second script - I'm not sure why there would be a script or executable called nohup as this would be against most rules of programming (naming a script the same as a command). The first script seems to have the syntax correct:
su - username -c "nohup /opt/user/scripts/test.sh &"
since running a nohup command is done like that, and added to su - user would be correct. See the man page for su and nohup.
$ file /opt/user/nohup : cannot open
$ ls -l /opt/user/nohup : not found
Since the nohup.out is created when the command is executed hence the file does not exist for the above 2 commands
If nohup.out is not writable in the current directory, output is redirected to $HOME/nohup.out; otherwise, nohup fails.
I have reason to believe you are incorrect in using ${HOME}/nohup in the second script If nohup.out is not writable in the current directory, output is redirected to $HOME/nohup.out; otherwise, nohup fails.
I need the nohup to be written at the /usr/bin/.I am not whether I am clear or not.
so , modify your second script to make it successfully run :
#!/bin/ksh
# This script calls the test script if the file exist
if [ -f /opt/user/scripts/test.sh ]
then
HOME="/opt/user"
echo "testing script"
su - username -c "/usr/bin/nohup /opt/user/scripts/test.sh &"
exit $?
fi
also ....
remove // in your script. use # if you want to put it as comments/remarks
I'm not sure whether you have put it purposefully.
su - username -c "${HOME}/nohup /opt/user/scripts/test.sh &
Seeing as "username"'s $HOME is (apparently) /opt/user - and nohup doesn't exist there, you are receiving the error that nohup can't be found.
Change that line of code to the line that bhargav has suggested (which was formulated from your earlier posting of the output of "which nohup") and your error should vanish!