- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: nohup an su command
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2008 02:07 PM
04-07-2008 02:07 PM
I'm trying to nohup, su, and then run a command and write it to a file - but no luck. Here's what I'm doing:
/usr/bin/nohup "/usr/bin/su oracle -c uptime" 2>&1 > /tmp/oratmp.txt &
I want the results of uptime to be written to /tmp/oratmp.txt - but it doesn't even get created.
What is my major malfunction?
Thanks all!
JC
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2008 02:59 PM
04-07-2008 02:59 PM
Re: nohup an su command
> /tmp/oratmp.txt 2>&1
Now the file descriptor 1 will be assigned to the filename and descriptor 2 will use what descriptor 1 is using.
/usr/bin/nohup and /usr/bin/su are OK ways to ensure your PATH doesn't pickup a rogue copy of the desired program but you have to be consistent (ie, /usr/bin/uptime). But a much better way to handle $PATH is to set it on the command line:
PATH=/usr/bin nohup su oracle -c uptime > /tmp/oratmp.txt 2>&1 &
The assignment of PATH on the command line is temporary so it doesn't affect your current $PATH value. For scripts, I always start with:
export PATH=/usr/bin
and then add additional paths as required. That way, my standalone scripts never inherit an unknown $PATH and run the wrong command.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2008 04:37 PM
04-07-2008 04:37 PM
Re: nohup an su command
use this:
/usr/bin/nohup "/usr/bin/su oracle -c uptime">> /tmp/oratmp.txt &
Thanks & Regards
Aashique
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2008 06:30 AM
04-08-2008 06:30 AM
Re: nohup an su command
I really appreciate the feedback, but I'm still coming up with an empty file.
Things that make you go HMMM?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2008 10:59 PM
04-08-2008 10:59 PM
Re: nohup an su command
/usr/bin/nohup "/usr/bin/su oracle -c uptime">> /tmp/oratmp.txt &
This doesn't look right but may work? The syntax for nohup is:
nohup command arguments
If you quote it, it is all one "command".
You would have to use tusc to see what's happening.
>but I'm still coming up with an empty file.
You may need to use tusc to see what's happening.
You can also break up the command into a script:
nohup script > /tmp/oratmp.txt 2>&1 &
And in the script use:
#!/usr/bin/sh
su oracle -c "uptime"
With a script you can add echo and "set -x" to debug.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2008 12:06 PM
04-09-2008 12:06 PM
Re: nohup an su command
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2008 03:22 PM
04-09-2008 03:22 PM
Re: nohup an su command
You use these only for debugging.
I had no problems doing this from root:
# nohup su xxxxxx -c "uptime" > /tmp/oratmp.txt 2>&1 &
So your original problem had to do with quoting the nohup options and your incorrect order of redirections.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2008 10:47 AM
04-10-2008 10:47 AM
Re: nohup an su command
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2008 12:22 PM
04-10-2008 12:22 PM
Re: nohup an su command
I'm not sure why?
What do you get for:
/usr/bin/nohup /usr/bin/su oracle -c "/usr/bin/uptime"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2008 06:15 AM
04-14-2008 06:15 AM
Re: nohup an su command
still nothing. Sorry, and thanks for your efforts.
JC
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2008 03:22 PM
04-14-2008 03:22 PM
Re: nohup an su command
I assume you are root and your shell is /sbin/sh and the user oracle exists?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-14-2008 04:19 PM
04-14-2008 04:19 PM
SolutionHow about just the basics? Start with:
/usr/bin/su - oracle
uptime
Notice the "-" with su? Unless you are very familiar with using su without the "-", always use su - so your session inherits the correct environment.
If the above works OK, now try it with PARTIAL redirection:
/usr/bin/su - oracle -c uptime > /tmp/oratmp.txt
The reason for partial is that you need to see the errors in case /tmp/oratmp.txt is causing a problem. (perhaps there is an existing file called oratmp.txt but owned by root and allowing no write access) Because stderr is redirected to stdout, failure to create the temp file will be invisible because the error message cannot be written out.
Now the same with complete redirection:
/usr/bin/su - oracle -c uptime > /tmp/oratmp.txt 2>&1
This should produce the desired output. Now remove the output file so you can see if it gets created again in the background:
rm /tmp/oratmp.txt
/usr/bin/su - oracle -c uptime > /tmp/oratmp.txt 2>&1 &
And if that works OK, try it with nohup as a last step:
rm /tmp/oratmp.txt
/usr/bin/nohup /usr/bin/su - oracle -c uptime > /tmp/oratmp.txt 2>&1 &
Another way to troubleshoot this would be to just remove the stderr redirection:
rm /tmp/oratmp.txt
/usr/bin/nohup /usr/bin/su - oracle -c uptime > /tmp/oratmp.txt &
Then look in the local file nohup.out. It will contain any stderr problems.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2008 07:06 PM
04-15-2008 07:06 PM
Re: nohup an su command
Bill - wow - thanks for the insight - I'll check it out and let you know - Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2008 03:15 PM
04-22-2008 03:15 PM
Re: nohup an su command
This worked as expected
____________________________________________
This worked as expected, writing the "su - oracle" output and the "uptime" output to the file, although there were some control characters in there between the two command outputs, shown here: ^[[3g ^[H ^[H ^[H ^[H ^[H
^[H ^[H ^[H ^[HCOLUMNS=80
____________________________________________
&1
This worked as expected also, writing the "su - oracle" output and the "uptime" output to the file, although there were some control characters in there between the two command outputs as above, and also the statement: "not a terminal"
___________________________________________
&1 &
This appeared to hang, until I hit the return key twice, and it gave it a sigterm kill. There was an empty output file generated.
____________________________________________
This also appeared to hang, until I hit the return key twice, and it gave it a sigterm kill. There was an empty output file generated.
____________________________________________
This also appeared to hang, until I hit the return key twice, and it gave it a sigterm kill. There was an empty output file generated, and there wasn't any nohup.out file created.
____________________________________________
Sorry to keep bugging - any other ideas?
Thanks,
JC
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-22-2008 04:26 PM
04-22-2008 04:26 PM
Re: nohup an su command
It's all obvious now. What shell are you using? If you are using the scummy C shell, I've had that hang happen!
You need to go through every stinkin' line of /etc/profile, ~/.profile, .login, .cshrc etc to make sure all tty commands are conditioned out if you aren't on a tty.
These shouldn't be there:
>some control characters in there between the two command outputs, shown here: ^[[3g ^[H ^[H ^[H ^[H ^[H^[H ^[H ^[H ^[HCOLUMNS=80
>also the statement: "not a terminal"
>This appeared to hang,
See Bill's comments about evil tty stuff in these links:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1155618
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1206345
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1146959
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1132303
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2008 05:21 AM
04-23-2008 05:21 AM
Re: nohup an su command
^[H ^[H ^[H ^[HCOLUMNS=80
Your oracle login is messed up bad with hardcoded TERM values and interactive terminal commands. You have to fix the oracle .profile to bypass terminal commands when running in batch -- as mentioned before.
Bill Hassell, sysadmin