•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 363,517 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,386 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser:
Views: 370 | Replies: 1
![]() |
•
•
Join Date: Apr 2008
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
Hi,
I have written a script file that first makes a ssh connection with the remote system and then does some job. My script file is as follows
The ssh connection is formed successfully. But sa is not printing anything. just a blank line
similarly sa3. But end is being printed. Both text files (1.txt and 2.txt)resides in the remote system. I know the problem is with this line
The command is not taking input from 1.txt which is residing on the remote system. Where am i going wrong.
I have written a script file that first makes a ssh connection with the remote system and then does some job. My script file is as follows
#! /bin/sh ssh 172.16.1.2 <<EOF sa=`/usr/sbin/alternatives --config java </root/Desktop/1.txt 2>&1 | grep jdk1.6.0_05` echo $sa sa2=`echo $sa | sed -e 's/[^0-9]//g'` sa3=`echo $sa2 | head -c 1 >/root/Desktop/2.txt` echo @sa3 echo "end" EOF
The ssh connection is formed successfully. But sa is not printing anything. just a blank line
similarly sa3. But end is being printed. Both text files (1.txt and 2.txt)resides in the remote system. I know the problem is with this line
sa=`/usr/sbin/alternatives --config java </root/Desktop/1.txt 2>&1 | grep jdk1.6.0_05`
The command is not taking input from 1.txt which is residing on the remote system. Where am i going wrong.
At the moment you are throwing away the output from running /etc/sbin/alternatives because it gets filtered through grep before you print the value of $sa.
Try:
Try:
#! /bin/sh ssh 172.16.1.2 <<EOF sa=`/usr/sbin/alternatives --config java 2>&1` echo "Result:" echo "$sa" echo echo "Will I find anything when I look in that result for jdk1.6.0_05 ???" echo "$sa" | grep "jdk1.6.0_05" echo "Nope. I thought not! But the reason should be clear now!" EOF
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb Shell Scripting Marketplace
Similar Threads
- seemingly popular problem with xorg/nvidia right now... (Window and Desktop Managers)
- ssh shell script (Shell Scripting)
- sendmail problem using cron (Shell Scripting)
- Problem somewhere between cable modem and router (Networking Hardware Configuration)
- SAMBA --> XP problem (*nix Software)
- Error in SSH (*nix Software)
- Possible Airport Problem? (Apple Hardware)
Other Threads in the Shell Scripting Forum
- Previous Thread: Running a script file from java
- Next Thread: shell script beautifier


Linear Mode