I'm just starting out with shell scripting and I'm trying to make a test where the script will basically run yum check-update to find out if the server has any available and if it does it e-mails me but if not it will just stop there.
I have it working if there are actually updates to be applied it works well. However, when I'm checking to see if the file is empty it seems to be sending out the e-mail anyway. The script I'm using is:
So I was just running the command and then trying to strip out the first few lines that I'm sending to my temp file because it will have stuff like "Connecting to RedHat Network, etc, etc" and then if it's blank I just want to exit, but if not it should just list the updates.
okay, that worked well. I'll have to test it on another box that has some updates because I updated my test machine to test the 2nd half.
Can you explain the syntax there for me? Originally I was trying something kind of like that within a single set of [] but what exactly is that one doing?
[[ ]] or [ ] act like "words" in shell. The word they almost exactly represent is "test".
So if you look up test documentation you find a lot of stuff you can test for.
is the equivalent to
and -s means 'Does the file exist and is the file size greater than zero (not empty)?'
! in front of the -s reverses the meaning because ! is the "not" operator.
Check out the other -[options] when you get a chance.
---------- Post updated at 02:08 PM ---------- Previous update was at 11:38 AM ----------
One last question...
what about if I wanted to look for a specific line of text in the output file. For example, if it said "No updates available" then exit but if not, run the mail command. Is that possible with something like grep -a ?
The below awk improved bu @MadeInGermany, works great as long as the input file has data in it in the below format:
input
chrX 25031028 25031925 chrX:25031028-25031925 ARX 631 18
chrX 25031028 25031925 chrX:25031028-25031925 ARX 632 14... (3 Replies)
Hi All,
I have a piece of perl code in which I DON'T want to delete a file rather empty out the contents, here is the code -
if ( unlink("$opt_b") == 1 ) {
print_log( "$opt_b deleted", 1 );
}else {
print_log( "Could not delete $opt_b:$!", 1 );
... (5 Replies)
Hi All,
I am checking for a empty input file to do some further action , but I am getting exit status 0 in both the cases , for empty and non empty file both.
The value of $? is coming 0 in if part also and else part too.
#!/bin/ksh
if ]; then
echo "data"
# exit 0
echo "$?"
else... (4 Replies)
hi
how can I determine, if a file is empty or not?I am using read line clause.
The script should be like:
while read line
do
if(file is empty) then;
......
done < $blacklist (1 Reply)
AIX 5.3 / KSH
I have a Java application which creates a log file a.log. I have a KSH script which does the following action
cp a.log /directory2/b.log
> a.log
After this the file size goes to 0 as per "ls -l"
Then next time when the application writes into this file, the file size... (4 Replies)