execute ssh command via perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting execute ssh command via perl
# 1  
Old 08-23-2012
execute ssh command via perl

Hi I have a perl command that doesn't seem to be working correctly. It appears to be fine but even when i try and run it manually same thing. Can someone take a look at this and tell me what they think the problem could be?

Here is the perl Line:

Code:
system ("echo 'ssh -t -t $user\@$_ \"cd $user_path; perl check_file.pl $email\" >> $upload_dir/$timedata/scp_log 2>&1' >> $upload_dir/waiting_list"

Now here is the manual line:

Code:
ssh -t -t john@myhostname 'cd /home/john/www/scripts;perl check_file.pl my_email@email.com'>> /home/john/www/test_log1 2>&1

When i didn't have the "cd" in the script, it just wouldn't work. Now when i had the cd option there the script processes but it i get a error saying:

Code:
sh: <application>: not found

but if i run the script manually by going to the file and typing
Code:
./check_file.pl my_email@email.com

works perfectly. starting to get frustrated here.

---------- Post updated at 01:33 PM ---------- Previous update was at 01:23 PM ----------

also to add i'm using aix 6.1
# 2  
Old 08-23-2012
You have written a perl script which generates shell scripts by running a shell script, which generates shell scripts and writes them to a file, presumably to run it in another shell later.

That's at least three separate, independent shells you're running there, to handle one line of "perl". If you have lots of system calls like this, your perl script is probably just thinly-disguised and uglified pure shell code, run with extraordinary inefficiency.

Could we see more of your code? I suspect the problem will become more evident. As well as better ways to solve the problem.
# 3  
Old 08-23-2012
Try this format:
Code:
system( "ssh -t -t $user\@$_ 'cd $user_path; perl check_file.pl $email >>$upload_dir/$timedata/scp_log 2>&1' >>$upload_dir/waiting_list" )

# 4  
Old 08-23-2012
I figured it out... thanks to all of those who tired to help.

The problem is this:

because the variables are set on that local user ID and not in the
Code:
/etc/profile

it was not noticing the program because it didn't know where to look. i just added for the program to execute the .profile before it continues anything.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute ssh command with additional terminal command to any remote user not working script

Hello i am having an issue with bash script and this is the code now=$(cat hosts1.txt | awk '{print $2;}') while read n ;do ssh root@$now 'useradd test1; echo -e "test1\ntest1" | passwd test1 && echo "test1 ALL=(ALL:ALL) ALL" >> /etc/sudoers' When i execute only part with cat, it... (8 Replies)
Discussion started by: tomislav91
8 Replies

2. Shell Programming and Scripting

Execute a command after ssh exits

In my .tcshrc I define and run an alias to set my terminal title. The title contains the hostname. I do this because I ssh to other machines a lot and I always need to know which host I am typing in. The alias is defined and run in the .tcshrc like this... alias tt 'echo -n "^0;`hostname -s`^G"'... (5 Replies)
Discussion started by: salvadorjoshua
5 Replies

3. Shell Programming and Scripting

Execute command on remote host via ssh

How should i make the following code working #!/bin/bash INPUTFILE="test.txt" while read STRING; do IP=`host -t A $STRING | awk '{print $NF}'` HOSTNAME=`ssh -oPasswordAuthentication=no -oStrictHostKeyChecking=no $IP "hostname"` echo $HOSTNAME > out.txt done < $INPUTFILE At this moment while... (3 Replies)
Discussion started by: urello
3 Replies

4. Shell Programming and Scripting

Execute command using ssh server 'cmd'

Hi The command below does not work as it require to take command in the breakers But If I do so the variable values get lost ssh testserver01 'dsmc q b "${ARCHIVE_DIR}*" -sub=yes -querysummary -inactive -fromd="${BACKUP_DATE}"' Thank you. (3 Replies)
Discussion started by: zam
3 Replies

5. UNIX for Dummies Questions & Answers

ssh command to execute shell script in another server

ssh -q <hostname> /opt/tcs/satish/tst.ksh ssh -q <anotherserver> /opt/tcs/satish/tst.ksh tst.ksh has "nohup <command> & " when i execute below script , its throwing error as nohup can not be found ssh -q <anotherserver> /opt/tcs/satish/tst.ksh > log & can someone let me... (5 Replies)
Discussion started by: only4satish
5 Replies

6. Shell Programming and Scripting

ssh execute command remotely

Hi all, Today I want to write a script to run the commands remotely. If I run the command as follows: ssh <user>@<ip> 'ls; pwd' it works fine. But when I want to use ssh to set view in clearcase, it will lose the response. as follows ssh <user>@<ip> 'cleartool setview <view_name>; pwd'... (1 Reply)
Discussion started by: Damon_Qu
1 Replies

7. Shell Programming and Scripting

SSH execute remote command (with jump)

Hi all, I am facing the following issue: Host A should execute a remote command (say pwd) on host B2. B2 is not directly reacheable but you have to connect from a to B1, then from B1 you can execute the command ssh user@B2 pwd. B1 and B2 are directly connected: A => B1 => B2 | ... (3 Replies)
Discussion started by: Evan
3 Replies

8. Shell Programming and Scripting

ssh to remote host and execute command

Hi, could anyone please tell me how to ssh to remote host foo and execute command on it and print the result on local host? Thanks, Paresh (1 Reply)
Discussion started by: masaniparesh
1 Replies

9. Shell Programming and Scripting

Net::SSH::Perl->Execute any unix command & display the output in a proper form

Net::SSH::Perl ...... how to print the output in a proper format my $cmd = "ls -l"; my $ssh = Net::SSH::Perl->new($host); $ssh->login($user, $pass); my($stdout, $stderr, $exit) = $ssh->cmd("$cmd"); print $stdout; the script works fine, but i am unable to see the output... (2 Replies)
Discussion started by: gsprasanna
2 Replies

10. Shell Programming and Scripting

How to execute remote ssh command - Perl and CGI

Hi, I am having nightmare issue-ing remote ssh command from a CGI perl script. It just won't run on debug message: It says permission denied. Can I even do this? as the apache server running under DAEMON account probably can't execute it? Is this the case of what's going on? Here is my... (3 Replies)
Discussion started by: Dabheeruz
3 Replies
Login or Register to Ask a Question