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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Insert title as output of command to appended file if no output from command
# 1  
Old 06-26-2015
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:
Code:
 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:

Code:
# $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()


Last edited by Don Cragun; 06-26-2015 at 03:46 AM.. Reason: Add CODE and ICODE tags.
# 2  
Old 06-26-2015
How about
Code:
TICLI "op:alarm,all" | { grep BATT || printf "Zero Battery Alarms\n"; } >>  outagereport

This User Gave Thanks to RudiC For This Post:
# 3  
Old 06-26-2015
Thanks, that works

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?
# 4  
Old 06-26-2015
Try
Code:
TICLI "op:alarm,all" | { grep BATT && echo "success" || printf "Zero Battery Alarms\n"; }

This User Gave Thanks to RudiC For This Post:
# 5  
Old 06-26-2015
wow that worked very well. I modified it to the following:

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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Getting command output to putty window title.

Hi, Last 2 weeks I have searched many forums and i haven't found the answer for the question: How to get all command output to Putty title? Needed it for other programs to know when some jobs on a server is done and is it done right or wrong. Plink stdout and stdin wasn't working, i used many... (1 Reply)
Discussion started by: domagaj
1 Replies

2. Shell Programming and Scripting

Treat Command Output as a File

Hi. Before I've post this question, I have spent hours looking for the solutions but to no avail. Because I think it is possible but I just don't know what is the right keyword to search for. Ok, basically what I want to achieve is really simple. It's just that I don't want to write... (20 Replies)
Discussion started by: aimy
20 Replies

3. Red Hat

Command understanding the output file destination in case of standard output!!!!!

I ran the following command. cat abc.c > abc.c I got message the following message from command cat: cat: abc.c : input file is same as the output file How the command came to know of the destination file name as the command is sending output to standard file. (3 Replies)
Discussion started by: ravisingh
3 Replies

4. Shell Programming and Scripting

Insert shell command into first line of output file

How can I insert the command executed on the shell into the first line of my output file? For example if I execute; zcat *.gz |grep “User5501” > users.out How can I make my users.out look like; zcat *.gz |grep “User5501” > users.out User5501 PA User5501 UA User5501 ZA... (3 Replies)
Discussion started by: lewk
3 Replies

5. UNIX for Dummies Questions & Answers

passing command output from one command to the next command in cshell

HI Guys, I hope you are well. I am trying to write a script that gets executed every time i open a shell (cshell). I have two questions about that 1) I need to enter these commands $ echo $DISPLAY $ setenv $DISPLAY output_of_echo_$display_command How can i write a... (2 Replies)
Discussion started by: kaaliakahn
2 Replies

6. Shell Programming and Scripting

to take the output of a command to a file

hi , i am using iostat -nmzx 1 | awk '{ print $4 }' command to get the i/o rates of disks. but i want command output in a file , how can i capture , this is some what difficult because command output is keep on changing , any way i have to get total output of the command . please help me .... (1 Reply)
Discussion started by: shankr3
1 Replies

7. Shell Programming and Scripting

Help me to command to output file format.

Dear Master. Help me to command to out put. Ex log. "<?xml version=""1.0"" encoding=""UTF-10"" ?><anova-test-bom> <txid>17251032659</txid> <authentication> <user>admin</user> <password>Amrduoi</password> </authentication> <destination> <msisdn>1111111</msisdn> ... (2 Replies)
Discussion started by: ooilinlove
2 Replies

8. UNIX for Dummies Questions & Answers

getting Output of ls command in a file

Hi I am trying to get the output of ls into a file with names seaparated with comma and no spaces. Here is the content of my dir: ls file1 file2 file3 file4this is what I tried: ls -m > list.txtthe file 'list.txt' looks like: file1, file2, file3, file4, list.txtI... (25 Replies)
Discussion started by: jdhahbi
25 Replies

9. Shell Programming and Scripting

Redirecting output of a command to a file

Hi We are having a requirement where one shell script, say a.sh (which uses Java and connects to Oracle database using JDBC) keeps on running everytime. I created a wrapper (to check whether a.sh is running and if not then to start it) and scheduled it in the crontab. Now all the output from... (3 Replies)
Discussion started by: ankitgoel
3 Replies

10. UNIX for Dummies Questions & Answers

Command display output on console and simultaneously save the command and its output

Hi folks, Please advise which command/command line shall I run; 1) to display the command and its output on console 2) simultaneous to save the command and its output on a file I tried tee command as follows; $ ps aux | grep mysql | tee /path/to/output.txt It displayed the... (7 Replies)
Discussion started by: satimis
7 Replies
Login or Register to Ask a Question