Using variables in SSH


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using variables in SSH
# 1  
Old 03-30-2009
Using variables in SSH

Please tell me what is wrong in the following shell script.

#!/bin/sh
DATE1=`date -d "yesterday" +"%Y-%m-%d"`
ssh ftwplapp01 << EOF
echo "Date is :" $DATE1 > /tmp/testfile
cd /app/was6/AppServer/logs/prod_ebp_live/ebp
tar cvf /app/was6/AppServer/logs/prod_ebp_live_applogs_$DATE1.tar `find . -name "*.log."$DATE1 -mtime -1`
EOF


DATE1 is not resolving under ssh. In other words, /tmp/testfile is not getting the value of $DATE1.

I'm getting following output:

was6@vmulport04:/app/weblogs/scripts> ./applogs_ftp.sh
Pseudo-terminal will not be allocated because stdin is not a terminal.

###############################################################################
Warning: These facilities are solely for the use of Authorized AIG Employees.
To protect systems from unauthorized use and to ensure that the system
is functioning properly, activities on this system are monitored and recorded
and subject to audit. Use of this system is expressed consent to such monitoring
and recording. Any unauthorized access or use of this system is prohibited and
could be subject to criminal and civil penalties.
###############################################################################

This server is participating in the eTrust project!
tar: Cowardly refusing to create an empty archive
Try `tar --help' or `tar --usage' for more information.

was6@vmulport04:/app/weblogs/scripts>


Please let me know what modification is needed to resolve this.

Thanks in advance.

Thanks,
Raja Yagna Narayanan T S
# 2  
Old 03-30-2009
When using Variables in a path or generally next to other characters, use {} around it like ${VAR}.

Try
Code:
tar cvf /app/was6/AppServer/logs/prod_ebp_live_applogs_${DATE1}.tar `find . -name "*.log.${DATE1}" -mtime -1`

If tar still says it refuses to create an empty archive, try the same "find" on the command line directly and see if it brings any useful output back.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Read several variables from command output via SSH

Hi Folks, I'm currently trying to read several values into different variables. Actually, what I'm doing works, but I get an error message. My attempts are: read strCPROC strIPROC strAPROC <<<$(ssh -n -T hscroot@$HMC "lshwres -r proc -m $strIDENT --level sys -F \"configurable_sys_proc_units... (11 Replies)
Discussion started by: NKaede
11 Replies

2. Solaris

Solaris 8 ssh issue - $SSH_ORIGINAL_COMMAND undefined variables

I face a weird question I don't know how to deal with. I tried to limit the permission of root user to remote login using ssh. So I did the following for a client server, 1. edit /usr/local/etc/sshd_config and modify as below PermitRootLogin forced-commands-only 2. using pubkey... (7 Replies)
Discussion started by: bestard
7 Replies

3. Shell Programming and Scripting

How to Simulate parallel-ssh with variables ??

alias n-001='ssh hst-net-001' alias n-002='ssh hst-net-002' alias n-003='ssh hst-net-003' alias n-004='ssh hst-net-004' alias p-001='ssh hst-proxy-001' alias p-002='ssh hst-proxy-002' alias p-003='ssh hst-proxy-003' alias p-004='ssh hst-proxy-004'... (0 Replies)
Discussion started by: lohith.dutta
0 Replies

4. Shell Programming and Scripting

ksh - keep argument variables after ssh

i have a script that should ssh to different host/server. See below: ./script.ksh var1 var2 var3 case $ser in ser1) depo='appr1' set -A aprrA aprrB ssh ser2 "/home/dir/script.ksh $1 $2 $3" ssh ser3 "/home/dir/script.ksh $1 $2 $3" ssh ser4... (4 Replies)
Discussion started by: erin00
4 Replies

5. Shell Programming and Scripting

Using a find command in ssh but using local variables?

I have a script like this (Yes, I know the DAY6 number isn't right - I'm just testing at this point): DAY0=`date -I` DAY1=`date -I -d "1 day ago"` DAY6=`date -I -d "2 days ago"` if then ssh root@synology1 nohup rm -rf "/volume1/Fileserver/$DAY6" fi I've tested the line to remove the... (5 Replies)
Discussion started by: Orionizer
5 Replies

6. Shell Programming and Scripting

Cannot create variables via ssh on remote machine

Hello to all Background info: Local machine : Linux, /bin/bash Remote machine (for the user used for ssh) : SunOs, /bin/ksh (so we have different OS, different Shells) My problem : From the local host i execute $ var=bla $ result=$(ssh -q user@remote-machine " > echo \"this is... (12 Replies)
Discussion started by: black_fender
12 Replies

7. Shell Programming and Scripting

Run recursive function with variables over SSH

Hi, I don't know if you can help or if this is even possible, but I am trying to run the following function over an ssh and (depending on the itteration I choose) keep getting unexpected token or undefined symbol errors. The function is: killtree() { typeset parent=$1 typeset child... (1 Reply)
Discussion started by: RECrerar
1 Replies

8. Shell Programming and Scripting

variables inside an ssh session

Hello all, I would like to declare and use variables inside an ssh session. I have the feeling that it's not possible. Here is the situtation simpified: #:/bin/sh test="salut" echo $test ssh hudson@10.41.21.99 <<EOF export testssh="salut" echo testssh=$testssh ... (4 Replies)
Discussion started by: Lotfus
4 Replies

9. Shell Programming and Scripting

Send Remote Commands via SSH with variables

Hi there I found the Command to send commands to other servers like: sv01> ssh user@sv02 'ps -ef' But I cant use Variables from a script i want to execute on another server like: sv01> ssh user@sv02 'cd $SCRIPTHOME' although the variable is set on sv01. How can I run commands on sv02 with... (2 Replies)
Discussion started by: DarkSwiss
2 Replies

10. Shell Programming and Scripting

Cannot read variables after ssh with rc file (KSH)

Greetings all, I'm currently making use of the $HOME/.ssh/rc file to launch an automated shell script immediately after the user has been verified through ssh. The current problem that I'm facing now is that I am unable to use the "read" command anymore... seems like the "read" statements are... (0 Replies)
Discussion started by: rockysfr
0 Replies
Login or Register to Ask a Question