0

I'm new to Bash and I have a problem that find difficult to solve, may be easy for some.

I have a really old SCO UnixWare 7 system with no SSH only RSH available. SCO doesn't exist anymore , I believe they are bankrupt. The box has been up for about 15 years never had a problem. We will move away from this platform in the summer however for now I need to copy some files to one of the Linux boxes and I'm trying to write a very short script. Please don't tell me that RSH is not secure since in this environment security is irrelevant. The UnixWare box and two other Linux boxes running CentOS 6 are dedicated and used by 3 people only to manage a number of barriers in a parking lot and not connected to the internet or any other network. Just 3 servers, connected to a 4 port standalone switch nothing else connected

Problem

I run this command on the Unixware server to set the variable on Linux1 running CentOS 6 with a formatted data and show the content:

rsh Linux1 "TEST=$(date --date='-9day' +%A_%B-%d_Backup); echo \$TEST" 

I get this error

# rsh Linux "TEST=$(date --date='-9day' +%A_%B-%d_Backup); echo \$TEST"
UX:date: ERROR: Illegal option -- -
UX:date: ERROR: Incorrect usage
UX:date: TO FIX: Usage:
        date [-u] [+format]
        date [-u] [[mmdd]HHMM | mmddHHMM[[cc]yy]]
        date [-a [-]sss.fff]

If I go to Linux2 also running CentOS 6 and run the same exact command against Linux1 I have no errors

[Linux2 ~]# rsh Linux1 "TEST=$(date --date='-9day' +%A_%B-%d_Backup); echo \$TEST"
Wednesday_January-14_Backup

Why is the command not working when ran from the UnixWare server? It seems that Unixware doesn't pass the string to Linux1 to process but tries to process it locally (there is no --date option on that ancient Unixware box, hence the error).

1

This isn't actually a UnixWare, Bash or RSH specific problem. It's a quoting problem, and it will affect any system that doesn't have the same date implementation as the remote system. For instance, it will also happen when SSHing from a Mac running Bash to a Linux box.

To make the remote system run date instead of the local one, adjust the quoting like so:

# rsh Linux1 'TEST=$(date --date=-9day +%A_%B-%d_Backup); echo $TEST'

Notice that we can skip some of the internal quoting and escaping this way, too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.