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.

#!/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"
#!/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?

@neutronscott

You probably don't want the quotes round EOF, it disables parameter substitution in the Here Document .

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

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

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:

/builds/foo/app123
/builds/bar/app456

or maybe its

/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:

#!/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.

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"

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:

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