Problems with remotely executing scripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problems with remotely executing scripts
# 1  
Old 10-21-2011
Error Problems with remotely executing scripts

Hi,

in the below command, i export a value to a variable which later is used by the script, however i dont see the exported value is actually been exported.

Code:
ssh user@host "export var=/path/ ; cd /path/ ; ./script"

how can i use the above command with proper value of var remotley
# 2  
Old 10-21-2011
It works for me...

Code:
cat run
 
#!/bin/bash
echo "My path is : $mypath"

Code:
ssh localhost "export mypath=/home2/aen/; cd /home2/aen/; ./run"
My path is : /home2/aen/

Check the usage of the variable in the script.

--ahamed
# 3  
Old 10-21-2011
You have to make your shell send a literal $ to the other end to use variables. That means putting things in single quotes, where the shell isn't allowed to substitute by itself.

One layer of quotes gets stripped out when you run the shell command, letting it substitute properly on the other side.

Code:
ssh user@host 'export var=/path/ ; cd "$var" ; ./script'

This User Gave Thanks to Corona688 For This Post:
# 4  
Old 10-21-2011
To illustrate the relative correct execution of ahamed:
Code:
ant:/home/vbe/z01 $ ssh an12 "export mypath=/etc/; cd $mypath; /home/vbe/run"
vbe@an12's password: 


I am now here :  /home/vbe
My path is : /etc/
ant:/home/vbe/z01 $ ssh an12 "export mypath=/etc/; cd $"mypath"; /home/vbe/run"
vbe@an12's password: 


I am now here :  /etc
My path is : /etc/
ant:/home/vbe/z01 $

Forgot run code...
Code:
an12:/home/vbe $ more run
#!/bin/ksh
echo "I am now here : " $(pwd)
echo "My path is : $mypath"
run: END

# 5  
Old 10-22-2011
Its still not working for me what i am doing is

Code:
user1@host1: ->ssh user@host "export DIR=/trumpet/uatuse1/uat/ogs/QUANTUM/NXT/data ; echo $DIR"

user1@host1: ->

# 6  
Old 10-22-2011
Try this and see if you are getting any output...
Code:
ssh user@host "echo 123"

--ahamed
# 7  
Old 10-26-2011
i get this

Code:
user1@host1 ->ssh user@host "echo 123"
123
user1@host1 ->

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remotely Executing Shell Script - Problems

Hey Lads, I have a shell script on a remote Server X that i need to execute from Server A. the script executes fine locally but remotely does not. It appears the script on the remote machine is calling another shell script which only has an array defined . Please see below the errors. ... (10 Replies)
Discussion started by: Irishboy24
10 Replies

2. Homework & Coursework Questions

Problems executing script

Hi, I'm a complete novice to Linux and UNIX. I'm having trouble getting a script to execute properly. I did a similar script earlier in the semester with no problems. For whatever reason I can't get this one to work. Any help would be greatly appreciated as I'm completely lost and frustrated at... (5 Replies)
Discussion started by: Lindy70
5 Replies

3. Debian

Problems with Crontab not executing scripts after edit

Hi all I installed Debian and i have a few scripts that outputs what is happening. The wierd part...after fresh install all works ok but after i open or edit Crontab it stops executing the scripts...and scripts runs manually so its not a problem with scripts...what happens is that i usually... (3 Replies)
Discussion started by: ro0t3d
3 Replies

4. Shell Programming and Scripting

Executing all scripts in /DIR except one

First i need to find all scripts directly under /DIR that end with ".sh" extension except "noallow.sh". That can be done with: find /DIR -maxdepth 1 -name "*.sh"|grep -v "noallow.sh" Now i want to run all the files output from the previous command. The following code: for filename in... (6 Replies)
Discussion started by: proactiveaditya
6 Replies

5. Shell Programming and Scripting

Executing scripts in Parallel

Hi All, I have 3 shell scripts, Script1,Script2 and Script3. Now I want to run Script1 and Script2 in parallel and Script3 should depend on successful completion of both Script1 and Script2. Could you please suggest an approach of acheiving this... Thanks in advance (2 Replies)
Discussion started by: itsme_maverick
2 Replies

6. HP-UX

Remotely connecting to HP-UX poses a lot of problems

1)MY HP-UX11iv2 machine is on a specific subnet as in rrr.rr.199.( its a rp3410 blade server).It has 2 hard disks one of them has HP-UX11iv2 and the other hard disk is not being used 2)ip of the hp-ux machine is rrr.rr.199.rrr 3)i need to access this hp-ux machine remotely from a windows machine... (3 Replies)
Discussion started by: rookie8278
3 Replies

7. Shell Programming and Scripting

Remotely executing awk command

ssh user@machine awk '{ split ($1,ar,"!");print ar}' samp >samp1 Error: Unmatched '. However on <machine> awk '{ split ($1,ar,"!");print ar}' samp >samp1 executes successfully. Any suggestions. (1 Reply)
Discussion started by: bishweshwar
1 Replies

8. Shell Programming and Scripting

Executing remotely the script

Hi All, I have a script to be executed in another machine. I connect to that machine from another server as a root ( this is the only configured access, as i cannot log in as a normal user). After that I have to switch to a normal user and that I can be able to executge that script. But all this... (12 Replies)
Discussion started by: elthox
12 Replies

9. UNIX for Dummies Questions & Answers

Executing Shell Scripts

Hi, I'm pretty new to Unix and I just have a question concerning making a script executable without putting the "sh" command before it. In case it makes the difference I am on an Apple computer using the Terminal. Anyway here is the little test code I wrote followed by the commands I took to try... (1 Reply)
Discussion started by: BuyoCat
1 Replies

10. UNIX for Advanced & Expert Users

executing perl scripts

Does anybody experiencing this same problem? I am using IRIX64 ver 6.5 at work. I wrote some Perl scripts and to execute it. First I try to put the Perl script at: /$HOME/bin/perlscript then I set the correct executable 755 right to the file I make sure the PATH to the executable... (2 Replies)
Discussion started by: vtran4270
2 Replies
Login or Register to Ask a Question