Question

estion 3 t out of 4 po 1) Write a bash script that checks for options passed to it. Use getopts and while loop as discussed in the classroom. Your script should: (i) Generate error messages (ii) Check for invalid options (ii) Check for options x and y, where option y must take an argument (iv) Print to the screen information informing which (if any) option was triggered 2) Explain your code (either in the comments to the code or underneath of it). Make sure to answer 1) and 2) above.
media%2F22f%2F22fb7493-2035-4149-ab6e-10
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#!/bin/bash -l
#PBS -l nodes=4:ppn=8,walltime=24:00:00

cat $PBS_NODEFILE | uniq | tr '\\012' ' ' > tmp-$PBS_JOBID
read -a NODE < tmp-$PBS_JOBID
rm tmp-$PBS_JOBID

inode=-1
ijob=0

usage() { echo "Usage: $0 [-s <45|90>] [-p <string>]" 1>&2; exit 1; }

while getopts ":s:p:" o; do
case "${o}" in
s)
s=${OPTARG}
((s == 45 || s == 90)) || usage
;;
p)
p=${OPTARG}
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))

if [ -z "${s}" ] || [ -z "${p}" ]; then
usage
fi

echo "s = ${s}"
echo "p = ${p}"


for ((K=1;K<=8;K++))
do
[ $((ijob++ % 2)) -eq 0 ] && ((inode++))
ssh ${NODE[inode]} _somepath_/RUN$K/sub.script &
done
wait
exit 0

Add a comment
Know the answer?
Add Answer to:
estion 3 t out of 4 po 1) Write a bash script that checks for options...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please write a BASH Script in LINUX that... 1. is actually executable 2. has a comment...

    Please write a BASH Script in LINUX that... 1. is actually executable 2. has a comment to tell us what you did, why and how. 3. allows a user to enter their name and a number between 1 than 100 (this must be prompted so the user knows what to do) 4. creates a random number between 1 and 100 for you to guess. The command to create a random number is shown below. (if you find a better one...use...

  • i need help with a mips program to to covert roman numerals to real numbers Lab 4: Roman Numeral Conversion Part A: Due...

    i need help with a mips program to to covert roman numerals to real numbers Lab 4: Roman Numeral Conversion Part A: Due Sunday, 19 May 2019, 11:59 PM Due Friday, 24 May 2019, 11:59 PM Part B: Minimum Submission Requirements Ensure that your Lab4 folder contains the following files (note the capitalization convention): o Diagram.pdf o Lab4. asm O README.txt Commit and push your repository Lab Objective In this lab, you will develop a more detailed understanding of how...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT