You can also use "$?" inorder to check the status code for the last executed command.
Pl dont direct the result to some dummy terminal(/dev/null). We generally do this when we dont need the output and even we dont want that output to be displayed on the screen. Please use the below code:
Returncode = `cd $Path;ls -lrt *$fdate 2>/dev/null | wc -l`
if [ "$Returncode" = 0 ]
then
echo '.......'
else
Vicky Narayan: in this case, $? will be the result code from wc -l, not from ls! But the idea to capture the result with backticks and not echo anything if it's zero is workable.
You still need to remove the spaces around the equals sign, it's a syntax error to leave them out.
However, if you really do need to distinguish between "error" and "no output" (wc -l will be zero in both cases). you will need to decompose it somehow. Maybe something like this:
If you need to do something more if ls fails, just add stuff to the "then" clause. You can also add an "else" clause to only do things when ls is successful. But notice that output from the whole if construction gets piped to wc -l or false (hope that works for you; not sure how portable that is, but this is a proof of concept anyway; change it to "cat >/dev/null" or something if you can't make it work with false.)
my requirement is returncode !=0
then list the all files in a directory.
Wait a minute. So you don't really care about wc -l at all?
ls files 2>/dev/null will list the files if they are there, and not display a warning if they are not, and set a non-zero exit code if it failed. If that's all you want then there you are.
Greetings Experts,
I am on AIX using ksh. Created a unix script which generates the CREATE OR REPLACE VIEW ... and GRANT .. statements, which are placed in a single .txt file. Now I need to execute the contents in the file (there are around 300 view creation and grant statements) in Oracle and... (4 Replies)
Hi. I m trying to figure out how to do this.
I have a directory full of files (100 files) and I want to be able to search for a string called "end" at the end of the files (last line or last 5 lines) and echo each file to say "incomplete" if not found.
This is what I have so far.
---... (4 Replies)
I am using the below code to ftp file onto another server
FTP_LOG_FILE=${CURR_PRG_NAME}- ${FTP_FILE}-`date +%Y%m%d%H%M%S`.log
ftp -ivn ${FTP_HOST} ${FTP_PORT} << ENDFTP >> ${EDI_LOG_DIR}/${FTP_LOG_FILE} 2>&1
user ${FTP_USER} ${FTP_PSWD}
lcd... (2 Replies)
# zpool status -v
pool: pool1
state: ONLINE
status: One or more devices has experienced an error resulting in data
corruption. Applications may be affected.
action: Restore the file in question if possible. Otherwise restore the
entire pool from backup.
see:... (0 Replies)
Hi,
I googled a bit, but could not find the answer to my problem.
But I am sure it is a common issue.
I have this code:
#!/bin/perl -w #-d
use strict;
sub remsh_test()
{
my $host = $_;
printf "\n----\n\n";
printf "remsh to $host with system call\n";
my $result = system... (3 Replies)
I need to know what the upload speed of an Internet connection. I thought the easiest way to do this would be to transfer a file via FTP to my server using the command:
sh-3.2$ ftp -u ftp://username:password@computerdomain/directory/ file_to_be_uploaded
Note: My environment allows me to issue... (2 Replies)
I want to capture actual error message in case the commands I use in my shell script fails.
For eg:
ls -l abc.txt 2>>errorlog.txt
In this case I understand the error message is written to the errorlog.txt and I assume its bacause the return code from the command ls -l abc might return 2 if... (3 Replies)
Hello All,
I'm very new to scripting and I'm writing a very simple script to restart a couple processes because I'm getting to lazy to cd between directories.
This is pretty much my first script and I just want to add a little cosmetics to it.
Here's what I have:
#!/bin/ksh
echo... (5 Replies)
Hi All,
I have a log file which consists of log messages as follows ->
GLOBALCALLID_CLUSTERID_B NEXT * , O(") CHARACTER
JOINONBEHALFOF NEXT * , O(") CHARACTER
Record 1: Rejected - Error on table IFA_MMV_CDR, column CDRRECORDTYPE.... (1 Reply)