1745790 Members
3955 Online
108722 Solutions
New Discussion юеВ

Compare two variables

 
SOLVED
Go to solution
Graham Van der vaart_1
Super Advisor

Compare two variables

Hi
I have a shell script:

#!/usr/bin/sh


NOW=`date +%b' '%e' '`
HR=22
SP=$NOW$HR


CHECK=`ll -tr /tmp/myfile*| awk ' { print $6,$7,substr
($8,1,2)}'|tail -n 1`


if [ "$SP" = "$CHECK" ]
then
{
echo "File did arrive at 22h00 today"
exit 0
}
else
{
echo "File did not arrive at 22h00 today"
exit 0
}
fi

I want to schedule this script to run at 22h05 to check if a new version of a file (myfile*) has arrived at 22h00.
No matter how I script the expression in the if statement it doesn't behave as expected.
What am I doing wrong?

Regards
Graham
3 REPLIES 3
Matti_Kurkela
Honored Contributor

Re: Compare two variables

Your awk expression produces an output like "Sep 8 10", with a single space between each element.

However, the date command produces two spaces between "Sep" and "8". The "%e" format code for the "date" command always output exactly two characters.

MK
MK
Hakki Aydin Ucar
Honored Contributor
Solution

Re: Compare two variables

>NOW=`date +%b' '%e' '`
Try this:
NOW=`date +%b%e`
Graham Van der vaart_1
Super Advisor

Re: Compare two variables

Thanks,

This works (and tested with |xd):


NOW=`date +%b%e`
HR=22
SP=$NOW" "$HR
echo $SP

CHECK=`ll -tr /tmp/myfile*| awk ' { print $6,$7,substr($8,1,2)}'|tail -n
1`
echo $CHECK

if [ "$SP" = "$CHECK" ]

Thanks again.