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