How to check if a command returns nothing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to check if a command returns nothing
# 1  
Old 05-21-2009
How to check if a command returns nothing

Hi, I want to write a script that runs a command (at -l) and writes the output to a file. If the command (at -l) command returns no value (is empty/null) then write a message to the file in place of the command output.

My problem is around trapping the empty returned command value and replacing with my own message. Checking $? returns success (0) as the command ran but the return from the command is empty.

Appreciate any help, thanks.
# 2  
Old 05-21-2009
Assuming at -l gives no output to stdout -
Code:
#!/bin/ksh
at -l > t.lis
if [[ -s t.lis ]] ; then
    echo 'we got a result'
else
    echo 'no result'
fi

# 3  
Old 05-21-2009
Many thanks, that works great!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Iscsiadm command returns error 'no records found'

Hi there, I'm currently working on an exercise to connect to a Windows iscsi target via a Red Hat initiator machine. I'm using Windows Server 2012 and Red Hat Enterprise Linux v7.1 I have created the target on the Windows Server box and the two devices can communicate with each other. Verified... (3 Replies)
Discussion started by: Tech87
3 Replies

2. UNIX for Beginners Questions & Answers

Linux find command returns nothing

Under one of my directories on server I have more than 500 files with different type and name. When I run the find command to list the files with 'ABC_DEFGH' in the begining of its name and older than 20 days, nothing is return as result. Though I know there are more than 400 files which their name... (10 Replies)
Discussion started by: Home
10 Replies

3. Shell Programming and Scripting

Command to check only Autosys running jobs with autorep like command

Hi, Is there any specific command to use to check only say Running jobs via autorep or similar command for Autosys? (0 Replies)
Discussion started by: sidnow
0 Replies

4. Shell Programming and Scripting

Script to check one command and if it fails moves to other command

Input is list of Server's, script is basically to remove old_rootvg, So it should check first command "alt_rootvg_op -X old_rootvg" if it passes move to next server and starts check and if it fails moves to other command "exportvg old_rootvg" for only that particular server. I came up with below,... (6 Replies)
Discussion started by: aix_admin_007
6 Replies

5. Shell Programming and Scripting

Source command returns error when it strikes conditional statement "ifeq"

Hello All, I am running source command on my project configuration file app.cfg which has conditional statements with make file systax E.g ifeq ($(APP_CMP_DIR),trunk). When I source this file it throws error: syntax error near unexpected token... (1 Reply)
Discussion started by: anand.shah
1 Replies

6. Shell Programming and Scripting

echo x - returns: x: command not found

I have been experiencing this problem intermittantly, I thought the problem was '/bin/sh -> /bin/dash' but I changed that to bash and the problem persists. I am writing functions to be included in user's '.bash_profile' through source or '.' filename a quick example of the problem is illustrated... (3 Replies)
Discussion started by: bsquared
3 Replies

7. Shell Programming and Scripting

If the grep command returns any result set

my intension is to use a grep command inside the shell script and if any row is returned or not.. depending on the resultset i have to code on further. how to check this i mean.. could anyone help me out with the if condition how to use it here !! (4 Replies)
Discussion started by: gotam
4 Replies

8. UNIX for Dummies Questions & Answers

find command returns files with spaces, mv won't work...

Hi guys. I am trying, to move files found with the find command... Script runs fine, until it reaches a file that contains spaces... Here is what i wrote up quickly. ROOTDIR=/apps/data SEARCH=$(find /data/HDTMPRestore/home/tmq/ -type f -print | grep Mods/Input/bck | cut -c19-) for i... (1 Reply)
Discussion started by: Stephan
1 Replies

9. UNIX for Dummies Questions & Answers

ps command returns a "?"

When I do the following command where jxh777 is my userid to see my processes, I see a question mark in the return. Does that mean anything ? ps -ef | grep jxh777 jxh777 9966 9965 0 16:47:46 pts/tb 0:00 -ksh jxh777 11660 9966 1 17:05:02 pts/tb 0:00 grep jhabi0 jxh777 28162 28160... (6 Replies)
Discussion started by: jxh461
6 Replies

10. UNIX for Dummies Questions & Answers

cant find command that returns blank line

This is my list of sed commands: can anyone tell me where im going wrong. The script works on a file called data which contains 6 student id's and there answers for 6 questions. !/bin/sh sed -e 's/*//g' \ #replace * with nothing -e s/ /X/g' \ #replacing empty space with X -e... (2 Replies)
Discussion started by: jeffersno1
2 Replies
Login or Register to Ask a Question