Need help in writing the shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help in writing the shell script
# 8  
Old 10-02-2008
The main question is, do you run it in a cron job every five minutes and if so how do you check whether the action should be to start or not, and when to send a report (and how)? If you run it in a loop the state (auditing or not) is easier to handle, but it might be less robust.

Code:
auditing=false
while true; do
  loggedin=$(who | grep '^gayathri ')
  if $auditing then
    case $loggedin in '') audit stop; auditing=false; send report;; esac
  else
    case $loggedin in '') ;; *) audit start; auditing=true;; esac
  fi
  sleep 300
done

But what if this script is terminated because the load gets too high or something? Then you don't know what the state is when you restart it.

Sorry for the awk faux pas; the correct way to code that would be something like

Code:
who | awk 'BEGIN { rc=1; } $1 == "gayathri" { rc=0; } END { exit rc }'

... but I guess the grep version is really better.

Last edited by era; 10-02-2008 at 08:17 AM.. Reason: Corrected awk script
# 9  
Old 10-02-2008
Quote:
Originally Posted by era
The main question is, do you run it in a cron job every five minutes and if so how do you check whether the action should be to start or not, and when to send a report (and how)? If you run it in a loop the state (auditing or not) is easier to handle, but it might be less robust.

But what if this script is terminated because the load gets too high or something? Then you don't know what the state is when you restart it.
Yep. That was my question as well.

Quote:

Sorry for the awk faux pas; the correct way to code that would be something like

Code:
who | awk 'BEGIN { rc=1; } $1 == "gayathri" { rc=0; } END { exit rc }'

... but I guess the grep version is really better.
Maybe, but Awk looks awksome offcourse. But I think both these problems might be an overkill for the problem gayathri is trying to solve; it's probably better to kick off the audit monitor and exclude those he doesn't want to monitor there.
# 10  
Old 10-02-2008
Era, thanks...when I tried to execute, I get the error:
0403-057 Syntax error at line 8 : `else' is not expected

However, I do not find anything wrong with the syntax. Any idea what it could mean??

Gayathri
# 11  
Old 10-02-2008
Well

Code:
auditing=false
while true; do
  loggedin=$(who | grep '^gayathri ')
  if $auditing
  then
    case $loggedin in '') audit stop; auditing=false; send report;; esac
  else
    case $loggedin in '') ;; *) audit start; auditing=true;; esac
  fi
  sleep 300
done

It worked well now!
# 12  
Old 10-02-2008
Code:
  if $auditing then

Or in the same line modification should be as

Code:
  if $auditing; then

# 13  
Old 10-02-2008
Clearly not my day today. Sorry for the error again.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Need help in writing shell script

Dear Team, Below is the list of steps i need to perform manually as of now and completely new to shell scripting, could you help in writing a shell script to perform the below procedure? 1. Log in to primary DNS server 2. Check /etc/named.conf if zone is already created (grep –i... (2 Replies)
Discussion started by: VKIRUPHAKARAN
2 Replies

2. UNIX for Dummies Questions & Answers

Need help writing shell script!

Hi, I'm very new to this, so bear with me please. I want to write a sh script (or if there's a better format please let me know) that allows me to, when I run it, print the date to a file (1.out) take 2 arguments (files a.fa and b.fa), run them with another program, outputting to 2.out, and then... (4 Replies)
Discussion started by: ShiGua
4 Replies

3. Shell Programming and Scripting

Need help writing shell script!

Hi, I'm very new to this, so bear with me please. I want to write a sh script (or if there's a better format please let me know) that allows me to, when I run it, print the date to a file (1.out) take 2 arguments (files a.fa and b.fa), run them with another program, outputting to 2.out, and then... (2 Replies)
Discussion started by: ShiGua
2 Replies

4. Shell Programming and Scripting

Writing a shell script

Hi I have two files a.log and b.log . i need to append a.log and b.log so that at the end of first line in a.log i need the append the data of first line from b.log and end of the second line in a.log i need to append the data of second line from b.log and so on up to the end of the file can... (3 Replies)
Discussion started by: lalu
3 Replies

5. UNIX and Linux Applications

Need help in writing shell script

I have written a shell script and when i ran the script,for some point of time it is asking to press enter key manually using keyboard.So i need it the enter key in shell itself. ex : in my shell script,i used the command ssh-keygen -t rsa so it asks the enter 3 times. can you please let me know... (3 Replies)
Discussion started by: lkeswar
3 Replies

6. Shell Programming and Scripting

Writing shell script

Hi, I am a new for shell script. i need to write script using the following commands cd /usres/test # create directory mkdir temp+DATE( i need to append date ) #moving files from one directory to this directory(we need to check total files in source and taget) cd /users/sample ... (2 Replies)
Discussion started by: bmkreddy
2 Replies

7. AIX

Difference between writing Unix Shell script and AIX Shell Scripts

Hi, Please give me the detailed Differences between writing Unix Shell script and AIX Shell Scripts. Thanks in advance..... (0 Replies)
Discussion started by: haroonec
0 Replies

8. Shell Programming and Scripting

Need help for writing shell script

Hello ALL, I am fresher in Unix . i need help to write small shell script . Please help me unix guru. I am developing the internal site in my office . the data files are generated in one directory everyday . I have to write shell script to sort those files and put it is internal site . ... (3 Replies)
Discussion started by: deepa20
3 Replies

9. UNIX for Dummies Questions & Answers

Writing a shell Script

How to write a shell script file to read 5 numbers using a while loop. Finding the average, maximum and minumum for the numbers. Any help would be great. (1 Reply)
Discussion started by: Chin
1 Replies

10. Shell Programming and Scripting

Need help with writing shell script

I have the following output. I want to write a script to check for 1. waits > 0 on all rowsand Ratio > .0. if true then send email. ========================= ROLLBACK SEGMENT CONTENTION ========================= If any ratio is > .01 then more rollback segments are needed NAME ... (1 Reply)
Discussion started by: jigarlakhani
1 Replies
Login or Register to Ask a Question