Script Help - Syntax Issues


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script Help - Syntax Issues
# 1  
Old 04-16-2009
Script Help - Syntax Issues

I have the last portion of an Open Step ping server shell script that is giving me issues that I need to adapt to Ubuntu 8.10 Client flavor of Unix. Can someone see what is wrong with the following:
Code:
# if there are servers that just went down or came back up, notify
#  with high importance
if [ -s /tmp/$SCRIPTNAME.serverlist.upagain -o -s /tmp/$SCRIPTNAME.serverlist.wentdown ]; then
  echo notifying of servers that are up again or just now down
  notify high
# if there is no new news, but servers are still down from before,
#  notify only once per day, with low importance
elif [ -s /tmp/$SCRIPTNAME.serverlist.stilldown ]; then
  if [ "`date | awk '{print $4}' | awk -F: '{print $1}'`" -eq 11 ]; then
    if [ ! -f /tmp/$SCRIPTNAME.stilldownsent ]; then
      touch /tmp/$SCRIPTNAME.stilldownsent
      echo notifying once today of servers that are still down from before
      notify low
    fi
  else
    echo not time for daily notification of servers that are still down
    if [ -f /tmp/$SCRIPTNAME.stilldownsent ]; then
      rm /tmp/$SCRIPTNAME.stilldownsent
    fi
  fi
else
  echo no notification to make
fi

Here is the output I get when this section runs:
Code:
++ date
++ awk '{print $4}'
++ awk -F: '{print $1}'
+ '[' 11 -eq 11 ']'
+ '[' '!' -f /tmp/ping_servers.sh.stilldownsent ']'
root@mpt1a02:/admin/scripts/crons#

so the script ends or errors out and I think its the syntax specifically in my date command is not Ubuntu friendly- does anyone know the Ubuntu variety of Unix enough to give me a hand? Many thanks!! Dale
# 2  
Old 04-16-2009
instead of:
Code:
"`date | awk '{print $4}' | awk -F: '{print $1}'`" -eq 11

try
Code:
"`date +%H`" -eq 11

# 3  
Old 04-16-2009
I'll give it a try. THANKS SO MUCH! This forum has been very helpful to me. I will be back in touch. Did you see anything else that looked suspicious? Dale
# 4  
Old 04-16-2009
Yeah, that works - THANKS! I can see the integer comparing itself againist 11 - very nice. but the script is still ending and not notifying the update (when a server comes back up). The script is supposed to compare from the last time it ran and current time it runs and update files with the results and compare them to see if there are any changes. If there are, it should email the updates. Would you mind taking another look?

Current output when script runs
Code:
 + read NAME IP ROUTER
++ grep -w Winchester2 /admin/scripts/crons/ping_servers.sh.serverlist.downlastrun
+ WASDOWN=
++ grep -w Winchester2 /admin/scripts/crons/ping_servers.sh.serverlist.down
+ ISDOWN=
+ '[' -n '' ']'
+ '[' -n '' ']'
+ '[' -z '' ']'
+ '[' -n '' ']'
+ read NAME IP ROUTER
+ '[' -s /tmp/ping_servers.sh.serverlist.upagain -o -s /tmp/ping_servers.sh.serverlist.wentdown ']'
+ '[' -s /tmp/ping_servers.sh.serverlist.stilldown ']'
++ date +%H
+ '[' 12 -eq 11 ']'
+ echo not time for daily notification of servers that are still down
not time for daily notification of servers that are still down
+ '[' -f /tmp/ping_servers.sh.stilldownsent ']'
root@mpt1a02:/admin/scripts/crons#

Here is the code of the script where it compares:

Code:
# look for differences
# in this section, we are looking for what servers just went down,
#  which ones just came back up, and which ones are still down from before
echo lists of recent downs and returns, and servers that remain down
>/tmp/$SCRIPTNAME.serverlist.wentdown
>/tmp/$SCRIPTNAME.serverlist.stilldown
>/tmp/$SCRIPTNAME.serverlist.upagain
while read NAME IP ROUTER
do
  WASDOWN=`grep -w $NAME  /admin/scripts/crons/$SCRIPTNAME.serverlist.downlastru
n`
  ISDOWN=`grep -w $NAME  /admin/scripts/crons/$SCRIPTNAME.serverlist.down`
  if [ -n "$WASDOWN" -a -n "$ISDOWN" ]; then
    echo "$ISDOWN (still down)" >>/tmp/$SCRIPTNAME.serverlist.stilldown
  fi
  if [ -n "$WASDOWN" -a -z "$ISDOWN" ]; then
    echo "$NAME $IP $ROUTER (up again)" >>/tmp/$SCRIPTNAME.serverlist.upagain
  fi
  if [ -z "$WASDOWN" -a -n "$ISDOWN" ]; then
    echo "$ISDOWN (just went down)" >>/tmp/$SCRIPTNAME.serverlist.wentdown
  fi
done</tmp/$SCRIPTNAME.serverlist
# cat /tmp/$SCRIPTNAME.serverlist.upagain /tmp/$SCRIPTNAME.serverlist.wentdown /
tmp/$SCRIPTNAME.serverlist.stilldown

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Issues with Expect Script

Hi, does the expect script tries to match for everyline on the screen irrespective of the prompts??? spawn ./Inst.sh expect "path? (Y/N)" send "Y\r" expect "folder path" send "$DIR1\r" expect "path? (Y/N)" send "Y\r" expect "folder path2" send "$DIR2\r" After the installer... (11 Replies)
Discussion started by: premseth
11 Replies

2. Shell Programming and Scripting

Script syntax help

#!/bin/bash if ; then echo "Lipsa IP"; exit; fi i=1 ip=$1 while ; do if ; then rand=`head -$i pass_file | tail -1` user=`echo $rand | awk '{print $1}'` pass=`echo $rand | awk '{print $2}'` CMD=`ps -eaf | grep -c mysql` if ; then ./mysql $ip $user $pass & else sleep 15... (6 Replies)
Discussion started by: galford
6 Replies

3. Programming

Python Script Issues

Gents, This is a follow up to my previous post: https://www.unix.com/shell-programming-scripting/217521-python-newbie-question-regex.html Here the latest function that I am having issues with: def find_all_flvs(url): soup = BeautifulSoup(urllib2.urlopen(url)) flvs = for... (2 Replies)
Discussion started by: metallica1973
2 Replies

4. Shell Programming and Scripting

Script issues

#!/bin/bash glist=`cat /etc/group | cut -d ":" -f1,4` ulist=`cat /etc/passwd | cut -d ":" -f1,6` for i in $glist do echo "$glist" done for i in $ulist do echo "$ulist" done chkgrp=`cat /etc/group | cut -d ":" -f1` for a in chkgrp do (4 Replies)
Discussion started by: mduduzi
4 Replies

5. Shell Programming and Scripting

Bash Script issues

So what i am trying to do is write a script that takes in any number of scrambeled words and unscrambles them. I have already addressed the issues of partial matches, exits silently if there are no matches, and finds words regardless of case that they were input. but while trying to get it so... (3 Replies)
Discussion started by: alindner
3 Replies

6. Shell Programming and Scripting

Syntax error calling TCL script from shell script

hello everyone i am beginner on shell scripting .and i am working on my project work on ad hoc network i wrote a batch (.sh) to do a looping and execute a tcl script i wrote before in each iteration ..but i got this problem " syntax error near unexpected token `('... (1 Reply)
Discussion started by: marcoss90
1 Replies

7. Shell Programming and Scripting

nslookup script but having syntax issues

Hi All i am creating a script to perform a nslookup on a specified host (so in otherwords it will be: zong(script name) 172.x.x.10(ip adress). i am scripting in tcsh. unfortunately i think i am doing something wrong as it keeps giving me syntax error. can someone help? @ num=1 set arg='ping... (2 Replies)
Discussion started by: brian112
2 Replies

8. Shell Programming and Scripting

Bash script issues

Hi. The below part of my bash script kicks out the following error message: $ ./extract_eod_report_stats_new.sh 2010-04-23 ./extract_eod_report_stats_new.sh: line 204: syntax error near unexpected token `(' ./extract_eod_report_stats_new.sh: line 204: `TRANSACTIONS_RECEIVED_TOP=`grep... (6 Replies)
Discussion started by: Peter.Lovell
6 Replies

9. Shell Programming and Scripting

for / foreach syntax issues (in bash or tcsh)

So I am new to unix, and actually anything outside drag and drop with the mouse (been learning for about a week so far) . I have been using the foreach command in tcsh because I am working on a group of files. Basically what I need is to insert part of the filename as the first line in the file.... (0 Replies)
Discussion started by: thepolypore
0 Replies

10. Shell Programming and Scripting

Telnet Script Issues

HI All Some body wrote to me this Telnet Script : #!/opt/perl/bin/perl $ip = $ARGV; die ("IP must be passed as an argument. $!\n") unless defined($ip); use Net::Telnet (); $handle = new Net::Telnet (Timeout => 10, Prompt => '/.*(#|>|\))\s*$/'); $handle->open("$ip");... (10 Replies)
Discussion started by: Darknight
10 Replies
Login or Register to Ask a Question