Script dosent work ?

Hi!

The given source script give me this error message:
Illegal variable name.

What is wrong with this script ?

Please help asap.


if [ $(date +%A) == "Friday" ]; then
        if [ -f backupfile ]; then
            cp backupfile /BACKUPFRIDAY/backupfile-`date +"%Y%m%d"`; 
        else 
            echo "friday backup file missing" | mail yourmail@ddress -s "missing backup" -; 
        fi;
    fi;

Open in new window

LVL 2
team2005Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

omarfaridCommented:
try

if [ $(date +%A) == "Friday" ]; then
        if [ -f backupfile ]; then
            cp backupfile  /BACKUPFRIDAY/backupfile-`date +"%Y%m%d"`
        else
            echo "friday backup file missing" | mail yourmail@ddress -s "missing backup"
        fi;
    fi;

if you still have problem run the script as

sh -x scriptname

and post output
0
team2005Author Commented:
Hi!

Still dosent work, but it give this output:

Line 24 : [Friday==Friday] : command not found

0
omarfaridCommented:

if [ $(date +%A) == "Friday" ]; then

It seams that you are not leaving space before and after ==

you may also try using = rather than ==
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

team2005Author Commented:
Hi"

Still dosent work ?

Tor
0
TintinCommented:
Run the script as

sh -x scriptname

and post the output.
0
torimarCommented:
Is the script set to use the bash shell?

#!bin/bash
0
team2005Author Commented:
Hi!

Yes, its set to use the bash shell.

Tor
0
omarfaridCommented:
can you post the output of

sh -x scriptname

as requested before?
0
team2005Author Commented:
Hi!

Have give you that aoutput:

Line 24 : [Friday==Friday] : command not found

Tor
0
zmoCommented:
hi, the code below works fine for me...
I just changed '==' to '=' like omarfarid suggested.

That's fun, I think I've already seen this code somewhere :p
#!/bin/sh
 
if [ $(date +%A) = "Friday" ]; then
        if [ -f backupfile ]; then
            cp backupfile /BACKUPFRIDAY/backupfile-`date +"%Y%m%d"`; 
        else 
            echo "friday backup file missing" | mail yourmail@ddress -s "missing backup" -; 
        fi;
fi;

Open in new window

0
omarfaridCommented:
here it shows that it is space problem. did you try to put space before and after the == and [ ]
0
team2005Author Commented:
Hi!!

Tryed zmo code, and works now :)

Split the points then :)

Thanks for help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux OS Dev

From novice to tech pro — start learning today.