Insert title as output of command to appended file if no output from command

I am using UNIX to create a script on our system. I have setup my commands to append their output to an outage file. However, some of the commands return no output and so I would like something to take their place.

What I need

The following command is placed at the prompt:

 TICLI "op:alarm,all" | grep BATT >>  outagereport 

If there is no alarm that matches BATT , I still want a title to append to the outagereport vi file. Such as, Zero Battery Alarms

How can this be done?

Python of script so far:

# $language = "python"
# $interface = "1.0"

def Main():
    crt.Screen.Synchronous = True
    crt.Screen.Send("ls" + chr(13))
    crt.Screen.WaitForString("hostname> ")
    crt.Screen.Send("rm outagereport" + chr(13))
    crt.Screen.WaitForString("hostname> ")
    crt.Screen.Send("TICLI " + chr(34) + "op:alarm,all" + chr(34) + " " + chr(124) + " grep BATT >>  outagereport " + chr(13))
    crt.Screen.WaitForString("hostname> ")
    crt.Screen.Send(chr(13))
    crt.Screen.WaitForString("hostname> ")
    crt.Screen.Send("TICLI " + chr(34) + "op:alarm,all" + chr(34) + " " + chr(124) + " grep COMM >>  outagereport " + chr(13))
    crt.Screen.WaitForString("hostname> ")
    crt.Screen.Send("TICLI " + chr(34) + "op:alarm,all" + chr(34) + " " + chr(124) + " grep  GEN " + chr(124) + " grep FAIL >>  outagereport " + chr(13))
    crt.Screen.WaitForString("hostname> ")
    crt.Screen.Send("TICLI " + chr(34) + "OP:CELL, OOS" + chr(34) + " " + chr(124) + " grep INDT  >>  outagereport " + chr(13))
    crt.Screen.Send(chr(13))
    crt.Screen.WaitForString("hostname> ")
    crt.Screen.Send("ls" + chr(13))
    crt.Screen.WaitForString("hostname> ")
    crt.Screen.Send("cat outagereport" + chr(13))

Main()

How about

TICLI "op:alarm,all" | { grep BATT || printf "Zero Battery Alarms\n"; } >>  outagereport
1 Like

Thank you for taking the time to look at that. It works perfectly for what I needed.

---------- Post updated at 02:35 AM ---------- Previous update was at 02:14 AM ----------

Could the line be edited further so that a different set of text is created and appended to the file in the event that the command returns results?

Try

TICLI "op:alarm,all" | { grep BATT && echo "success" || printf "Zero Battery Alarms\n"; } 
1 Like

wow that worked very well. I modified it to the following:

   
  TICLI "op:alarm,all" | {  printf "San Antonio Generators Running\n" && grep GEN | grep RUN || printf "San Antonio Generator Alarms: Zero 0 \n"; }>> outagereport