Issues for script that login to a unix box


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Issues for script that login to a unix box
# 1  
Old 06-12-2012
Issues for script that login to a unix box

Hi,

I have a script that should login to a different box then the box that i am in and run the commands.

I have the script sample below that logins to a unix box and get the files .Looks like ls-lrt command is not running or its wrongly used.

Code:
#!/bin/bash
# Ask the user for build month
echo "Enter the Build Month: "
     read BuildNumber
# get the builds
 ssh user@box1  "cd /builds"
 ls -lrt | awk -F\/ '/\//{print $(NF-1) $NF }' | grep "$BuildNumber"

# 2  
Old 06-12-2012
Code:
#!/bin/bash
# Ask the user for build month
echo "Enter the Build Month: "
     read BuildNumber
# get the builds
 ssh user@box1  <<'EOF'
cd /builds
ls -lrt | awk -F\/ '/\//{print $(NF-1) $NF }' | grep "$BuildNumber"
EOF

though the ls line is flawed anyway. what exactly is the directory structure?

Last edited by neutronscott; 06-12-2012 at 01:37 PM.. Reason: forgot EOF
# 3  
Old 06-12-2012
@neutronscott
Quote:
ssh user@box1 <<'EOF'
You probably don't want the quotes round EOF, it disables parameter substitution in the Here Document .

Code:
cat <<'EOF'
1:$SHELL
EOF
cat <<EOF
2:$SHELL
EOF

./scriptname
1:$SHELL
2:/sbin/sh

# 4  
Old 06-12-2012
Well I meant to quote it... To show how one usually wants to send a script to stdin on remote host. Usually one does want the parameter expansion done on the remote host. You'd otherwise need to be more careful. Ideally you'd replace the ls with a more appropriate function. Without knowing what's in /builds it's hard to guess. But seeing that he's splitting at / and printing the last two, I'd expect something like:

Code:
/builds/foo/app123
/builds/bar/app456

or maybe its
Code:
/builds/build.1234/app
/builds/build.5678/app

But anyway, in regards to passing a script the a remote host, I'd start with something like this:

Code:
#!/bin/bash
read -p 'Build number: ' buildNumber
ssh mute@localhost sh -s "$buildNumber" <<'EOF'
cd /builds
ls -lrt ./*/* | awk -F\/ '/\//{print $(NF-1) $NF }' | grep "$1"
EOF

but the real issue is what is the structure of the directory so we can avoid parsing ls and having false matches and such.
# 5  
Old 06-12-2012
Thanks all, @neutronscott--the code kind of work , i get the files from the directory for the box specified but gets all the files, not reading the user input.

If i hardcode the build name , i get all the matches for March .
ls -lrt ./*/* | awk -F\/ '/\//{print $(NF-1) $NF }' | grep "March"

looks like something wrong at
grep "$1"
# 6  
Old 06-12-2012
I tested it. Are you certain you used sh -s "$buildNumber" <<'EOF'?
You could as methyl said use an unquoted here-doc in this instance:

Code:
ssh u@h sh -s <<EOF
cd /builds ls -lrt ./*/* | awk -F\/ '/\//{print $(NF-1) $NF }' | grep "$buildNumber"
EOF

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Remote login UNIX box from java passing parameters to the custom script called in the profile

Hello Good Day / Guten Tag.... I have to login the server and the user profile contains some scripts which need the inputs to be taken from the keyboard. So I use the method to conn.authenticateWithKeyboardInteractive(username, new InteractiveCallback() { public String... (1 Reply)
Discussion started by: Sanalkumaran
1 Replies

2. Linux

Linux script for multiple box login.

Hello! We currently use a SecureCRT .vbs script which automates logging into multiple boxes to run a few commands. However, I'd like to have something run in Linux vs. our emulator. Below is my objective :): Our current .vbs script will look at an IP list .txt file on our PC, then login to... (1 Reply)
Discussion started by: birdboyee
1 Replies

3. UNIX for Dummies Questions & Answers

DNS on Unix box issues

Hi Guys, Just wanted to seek your assistance on an issue encountered with one of our client DNS server query. we have 2 sets of DNS servers.. internal and external. For Internal to reach the external DNS server (DMZ) it has to go through 2 FWs. Current settings: - FW rules for Internal... (3 Replies)
Discussion started by: Hotshot8259
3 Replies

4. Linux

How to find remote Linux box login account without login in to that box?

Hi, How to find remote Linux box login account without login in to that box? I don't have login account at my remote Linux box. But I need who are all having login account. How do I findout? Thanks, --Muthu. (3 Replies)
Discussion started by: Muthuselvan
3 Replies

5. Shell Programming and Scripting

ftp file starting with particular name on Windows box to Unix box using shell script

Hello all ! I'm trying to write a shell script (bash) to ftp a file starting with particular name like "Latest_" that is present on a Windows box to UNIX server. Basically I want to set this script in the cron so that daily the new build that is posted on the Windows box can be downloaded to the... (2 Replies)
Discussion started by: vijayb4u83
2 Replies

6. Shell Programming and Scripting

how to use ssh-keygen to login to a UNIX box

I have to login with ssh to a UNIX box and execute a script in it. How will i make use of ssh-keygen so that while login using ssh it wont ask the passwod. ssh-copy-id is not working in my UNIX box . What might be the reason. Please help. (1 Reply)
Discussion started by: codeman007
1 Replies

7. UNIX for Dummies Questions & Answers

Running UNIX commands remotely in Windows box from Unix box – avoid entering password

I am able to run the UNIX commands in a Windows box from a UNIX box through "SSH" functionality. But whenever the SSH connection is established between UNIX and Windows, password for windows box is being asked. Is there a way to avoid asking password whenever the SSH connection is made? Can I... (1 Reply)
Discussion started by: D.kalpana
1 Replies

8. Shell Programming and Scripting

calling a unix script in one box from another box

i have a unix script which is available in a box say box1 i want this script to be run in box box2 and put the output file in box2 what is the procedure to execute this script in box2 i will call the script in box1 using cybermation (1 Reply)
Discussion started by: trichyselva
1 Replies

9. AIX

Vi opens automatically when i login to a unix box

When I login to a unix box using a putty session , I'm landed in a vi editor, instead of my home directory,I'm guessing instead of pointing me to my home directory, the system points me to /usr/bin/vi. As a result, everytime I log into the system I open up a vi editor and am in there. how do i... (3 Replies)
Discussion started by: ramky79
3 Replies
Login or Register to Ask a Question