nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

script for mailing to user the o/p of the script

This is a discussion on script for mailing to user the o/p of the script within the Shell scripting forums, part of the Development/Scripting category; I want to write a script that mails the user the o/p of a script. How can we do this. ...


Go Back   nixCraft Linux Forum > Development/Scripting > Shell scripting

Register FAQ Members List Calendar Forgotten your password? Mark Forums Read
  #1 (permalink)  
Old 08-17-2005, 01:01 PM
Member
User
 
Join Date: Jul 2005
Posts: 85
Rep Power: 0
ricc
Default script for mailing to user the o/p of the script

I want to write a script that mails the user the o/p of a script. How can we do this.

suppose, the code is something like this:

Code:
#!/bin/bash
#lets name the file getusrlog
ulog=~/userslog
oulog=~/olduserlog
mv $ulog $oulog
cat /dev/null > $ulog

for i in $(who |cut -f1 -d" "|grep -vE "(^-|this|the)" )
do 
    echo "These are the users logged on : $i `date '+on %d-%m-%y at %H-%M-%S'`">>$ulog
done 

if [ $? = 0 ]
then 
      echo "Program $0 completed successfully" >> $ulog
else
      echo "Program $0 failed" >> $ulog
fi

mail _______________# mail the user the contents of $ulog( i don't know how to do it)
Help in any way possible is always welcome.

Thanks

rc
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-17-2005, 03:22 PM
sweta's Avatar
Contributors
User
 
Join Date: Feb 2005
Location: New Delhi
My distro: Suse, RHEL, Vista
Posts: 154
Rep Power: 4
sweta will become famous soon enough
Default

Simple use mail command
mail -s "SUBJECT" myemail@somewhere.com < /tmp/file.txt

So to send an email from your script( add to end of your above script):
Code:
EMAILID=”me@yahoo.com”
mail  -s "Output of $0 script“  “$EMAILID” <$ULOG
If you wish to send file $ULOG as attachment then consider reading vivek's post
sending an mail with attachment using mutt http://www.cyberciti.biz/nixcraft/vi...ttachment.html
Reply With Quote
  #3 (permalink)  
Old 07-09-2007, 09:42 PM
Junior Member
User
 
Join Date: Jul 2007
My distro: Ubuntu
Posts: 5
Rep Power: 0
SAYAYINX is on a distinguished road
Send a message via AIM to SAYAYINX Send a message via Yahoo to SAYAYINX
Default Help

I do not have the mail command in my system, is mail the same as mailx?

~Saya
Reply With Quote
  #4 (permalink)  
Old 07-11-2007, 05:59 AM
nixcraft's Avatar
Never say die
User
 
Join Date: Jan 2005
Location: BIOS
My distro: Ubuntu
Posts: 1,060
Rep Power: 10
nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute nixcraft has a reputation beyond repute
Default

Quote:
Originally Posted by SAYAYINX View Post
I do not have the mail command in my system, is mail the same as mailx?

~Saya
Yes, mailx is same as mail on man y Linux and UNIX systems
__________________
Vivek | My personal blog
Linux Evangelist
Play hard stay cool
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
calling a script within a script Predatorian Shell scripting 2 04-07-2008 02:59 AM
Alphabetical file name and list logged in user script oronno Shell scripting 5 08-22-2007 01:10 PM
How can i create script for deleting user? Paul Shell scripting 1 08-02-2007 11:20 PM
Shell script or code for deleting a user narasimha.reddygnv Shell scripting 5 03-19-2007 11:07 AM
script who will control user processess darknet Shell scripting 2 01-02-2007 11:40 PM


All times are GMT +5.5. The time now is 04:54 PM.


Powered by vBulletin® Version 3.7.4 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36