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?
 
omarfaridConnect With a Mentor Commented:

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

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

you may also try using = rather than ==
0
 
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
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
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
 
zmoConnect With a Mentor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.