LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-23-2012, 05:12 AM   #1
kingston
Member
 
Registered: Mar 2008
Location: Bengaluru, India
Distribution: RHEL 5.5, Solaris 5.10
Posts: 215
Blog Entries: 1

Rep: Reputation: 21
Simple Script : But didnt work as i expect


Hi All

I am trying to find the users who are all using emacs editor in my linux server and i wrote the following script.

Quote:
#!/bin/bash
#This script is used to find the usage of emacs
#Whether it is being used or not and
#Who and When using the same.

user=`ps -ef |grep emacs |awk '{print $1}'|grep -v root`
process=`ps -ef |grep emacs |awk '{print $8}'|grep -v gre`

echo $user > one.txt
echo $process >> one.txt

`mail -s "$process invoked by $user" kingston@win.com < one.txt
The output is as follows, with the subject "emacs"
Quote:
/bin/bash
/bin/bash
emacs invoked by mursir
kinved

mursir kinved
emacs /bin/bash /bin/bash emacs
What i expect is a mail with the subject "emacs invoked by mursir kinved", with the following content
mursir kinved
emacs emacs

When i fired the individual commands, i have got the following outputs.

Quote:
[root@einbalx0014 ~]# user=`ps -ef |grep emacs |awk '{print $1}'|grep -v root`
[root@einbalx0014 ~]# echo $user
mursir kinved
[root@einbalx0014 ~]# process=`ps -ef |grep emacs |awk '{print $8}'|grep -v gre`
[root@einbalx0014 ~]# echo $process
emacs emacs
Can someone help me to attain the expected result?
 
Old 04-23-2012, 07:32 AM   #2
Ser Olmy
Senior Member
 
Registered: Jan 2012
Distribution: Slackware
Posts: 2,445

Rep: Reputation: Disabled
I removed the backtick in front of the mail command, and received a mail with the names of all users running emacs on one line, and a line below saying "emacs emacs emacs" etc.
 
Old 04-24-2012, 02:24 AM   #3
kingston
Member
 
Registered: Mar 2008
Location: Bengaluru, India
Distribution: RHEL 5.5, Solaris 5.10
Posts: 215
Blog Entries: 1

Original Poster
Rep: Reputation: 21
@ser_omly. Thanks for your reply. But it is not working for me still at the same time, i write this script in a different way and working fine.
Quote:

#This script is used to find the usage of emacs editor
rm -rf 1
rm -rf 2
touch 1
touch 2
for i in `ps -ef |grep emacs |awk '{print $1}'|grep -v root`
do
echo $i >> 1
done
for j in `ps -ef |grep emacs |awk '{print $8}'|grep -v gre`
do
echo $j >> 2
done
touch one.txt
presize=`ls -l one.txt |awk '{print $5}'`

paste 1 2 |pr -t -e20 > one.txt

if [[ -s one.txt ]] ## This Part will check the file one.txt
## is a empty one or not. If it is a empty one
## there is no need to alert the System Admin
then
cursize=`ls -l one.txt |awk '{print $5}'`
if [[ $cursize -gt $presize ]]
then
mail -s "emacs editor invoked" kingston.vedanayagam@hp.com < one.txt
else
touch one.txt
fi
else
#echo "no one is using emacs as of now"
touch one.txt
fi

Last edited by kingston; 04-24-2012 at 04:33 AM. Reason: Typo Err
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Expect script: how do i send function key F12 in an expect script alix123 Programming 4 09-01-2013 09:06 PM
Expect script with loop does not work zongbot Programming 5 08-31-2011 01:19 PM
[SOLVED] /usr/bin/expect : Script to check server load using both expect and bash Soji Antony Programming 1 07-27-2010 11:27 PM
Very simple script does not work....? M$ISBS Programming 7 01-28-2008 03:18 PM


All times are GMT -5. The time now is 03:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration