- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: unix script
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
06-04-2008 12:48 AM
06-04-2008 12:48 AM
I need some help with a unix script. Basically, I would like the script to email to me a log that it generated. The line that generates the script is :
exec > /test/`basename $0`_`date +%d-%b-%H:%M`.log 2>&1
Is is correct for me to issue the next line in the script as :
mailx -s "Log file" myname@mymail.com <&1
Not sure if this makes sense as I'm a newbie at writing scripts.
Thanks in advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2008 02:50 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2008 03:38 AM
06-04-2008 03:38 AM
Re: unix script
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2008 04:57 AM
06-04-2008 04:57 AM
Re: unix script
The -m is required when attaching a file using mailx on HP-UX.
Example
uuencode /tmp/mylog.log mylog.doc | mailx -m -s "my important log" someone@important.ca
This will send the mylog.log but rename it as mylog.doc. Handy when you receive the email. When you double click the attachment it will open in Word or whichever app is setup to open .doc files.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2008 05:19 PM
06-04-2008 05:19 PM
Re: unix script
Thanks for your reply.
Would you be able to explain the lines :
"exec 3>&1 4>&2 >$LOGFILE 2>&1" & "exec 1>&3 2>&4"
I know that 0 is stdin, 1 is stdout, 2 is stderr but what's 3 & 4? I'm really not good at this - apologies.
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2008 05:23 PM
06-04-2008 05:23 PM
Re: unix script
Thanks for your replies.
That's a very elegant way of doing it !
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2008 06:51 PM
06-04-2008 06:51 PM
Re: unix script
"exec 3>&1 4>&2 >$LOGFILE 2>&1" & "exec 1>&3 2>&4"
This is shell trickery.
Basically it dups file 1 to file 3 and file 2 to file 4 (saves them).
Then the second one puts those files back.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2008 09:10 PM
06-04-2008 09:10 PM
Re: unix script
exec 3>&1 4>&2 >afile.log 2>anotherfile.log
save fildescriptor 1 to 3 and 2 to 4
before redirecting them to files
and after to put back the filedesc in place
better way
exec 1>&3 2>&4 3<&- 4<&-
3<&- 4<&- close the dupped fildescripor after recovering the initial outputs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2008 10:44 PM
06-04-2008 10:44 PM
Re: unix script
Thanks so much for the help and explanation.
Laurent : I've tried your script and it worked beautifully. Thanks once again !