1

I am working on a shell script and python script as well. Python script is passing certain parameters to my shell script and then I am using those parameters in my shell script.

Below is my shell script -

#!/bin/bash

readonly MACHINES=(machineB machineC)
readonly MAPPED_LOCATION=/bat/peta/t1_snapshot
readonly FILE_TIMESTAMP=$file_timestamp

// old code which I am using to get the full path of the latest folder in each machine
dir1=$(ssh -o "StrictHostKeyChecking no" david@${MACHINES[0]} ls -dt1 "$MAPPED_LOCATION"/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] | head -n1)
dir2=$(ssh -o "StrictHostKeyChecking no" david@${MACHINES[1]} ls -dt1 "$MAPPED_LOCATION"/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] | head -n1)

echo $dir1
echo $dir2

// not sure what should I do here?
dir3=$MAPPED_LOCATION/$FILE_TIMESTAMP

In each machine (machineB and machineC), there will be a folder in this format YYYYMMDD inside this folder MAPPED_LOCATION.

Now what I am trying to do is - I am passing file_timestamp from the python script which will be in this form YYYYMMDD so now I need to check whether this folder is there inside MAPPED_LOCATION folder or not in each machine.

If it is there then print out the full path of that folder for each machine, otherwise exit out of the shell script with non-zero status. If it is not there in any one of the machine, I will exit out of the shell script with a message that this folder is not present in this machine with non zero status.

I am not sure how can I do this check in the shell script?

2
d="${MAPPED_LOCATION}/$(python_script)" 
[ -d "$d" ] && echo "$d" || exit 1
  • 2
    What is python_script here? And can you add some description which will be useful for my understanding purpose.? – SSH Apr 12 '14 at 2:44
  • $(python_script) is your python_script – mikeserv Apr 12 '14 at 4:49
  • or it should be $FILE_TIMESTAMP? – SSH Apr 12 '14 at 5:37
  • 2
    @SSH I don't know - it's your script. By the way, You should know what it does. I recognize this, you know, though you're using a different username. I remember all the nonsense you went through before to get other people to do this for you. Does your boss know that random people from the internet are writing the code that handles backing up/restoring your datacenters and you have no idea what it does? – mikeserv Apr 12 '14 at 5:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.