0

Below is the script i wrote.

#!/usr/bin/expect -f
#!/bin/bash

# connect via scp

Y_DATE=`$(date --date yesterday "+%Y-%m-%d")`

spawn scp /apps/Train/jboss-soa-p.5.0.0/jboss-as/server/default/log/server.log.$Y_DATE  "xxxx@Tdev:/apps/software/copiedLogFiles/"

expect "password:"
send "buildadmin\$123\r"
expect "*\r"
expect "\r"

and i am getting below error while executing script.

can't read "(date --date yesterday "+%Y-%m-%d")": no such variable
    while executing
"Y_DATE=`$(date --date yesterday "+%Y-%m-%d")`"
    (file "./copySITtoUAT_CDS.sh" line 6)

I am not able to figure out what's the error in Y_DATE declaration? Am i missing something here.

3 Answers 3

2

Maybe it is this: You can use either

Y_DATE=$(date --date yesterday "+%Y-%m-%d")

or

Y_DATE=`date --date yesterday "+%Y-%m-%d"`

But not both.

Sign up to request clarification or add additional context in comments.

1 Comment

Preferably $() (simplifies when it gets to nesting).
0

I modified my script as below and it worked.

#!/bin/sh

LOG_DIR=/apps/jboss/jboss-soa-p.5.0.0/jboss-as/server/mssql_prod1/log
SRS_HOST=XPSIT
USER_ID=xambas
PSWD=abackc
Y_DIR=`find $LOG_DIR -name "server.log*" \( -mtime -1 -and -not -daystart -mtime 0 \)`
cd $LOG_DIR
Y_FILE=`find . -name "server.log*" \( -mtime -1 -and -not -daystart -mtime 0 \)`
cd -
export Y_FILE SRS_HOST USER_ID PSWD Y_DIR

expect -c '
        spawn scp "$env(Y_DIR)" "$env(USER_ID)@$env(SRS_HOST):/apps/soft/Prod_LOG/Prod_A/$env(Y_FILE)"
        expect "password:"
        send "$env(PSWD)\r"
        expect "*\r"
        expect "\r"

Comments

0

The following code works :

Y_DATE=`date --date yesterday +%Y-%m-%d`

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.