LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-15-2013, 02:21 AM   #1
chrisb2244
LQ Newbie
 
Registered: Oct 2013
Posts: 2

Rep: Reputation: Disabled
Post Passing script options/arguments out of a subshell to a .sh file set of commands


Hi,

I am wondering if it is possible to use command line arguments to make small modifications to a file.sh that I have and use to submit jobs to a computing cluster using qsub, or if failing this I can write a separate script to generate a suitable file to submit.

Currently, I have something like
Code:
#!/bin/bash
showopts () {
while getopts ":q:n:j:" optname
do
case "$optname" in

"q")
$OPTARG < queueType
;;

"n")
$OPTARG < jobName
;;

"j")
$OPTARG < progToExecute
;;

":")
echo "No argument value for option $OPTARG"
;;
*)
echo "Unknown error while processing options"
;;

esac
done

return $OPTIND
}


PROGTOEXECUTE=$progToExecute
echo "$PROGTOEXECUTE"
QUEUETYPE=$jobName
echo "$QUEUETYPE"
JOBname=$queueType
echo "$JOBname"

#$ -S /bin/bash
#$ -cwd
#$ -N $JOBname
#$ -q $QUEUETYPE
#$ -M email.address
#$ -j no
#$ -l h_vmem=2.5g
#$ -l virtual_free=1.5g
#$ -m abe

$PROGTOEXECUTE > statusLog$JOB_NAME
The sh file that I normally submit is the section at the bottom - starting at #$ -S /bin/bash and running to the end of the code section.
The earlier part of the code is my attempt to move the information sent to the script out of a subshell, but clearly I have misunderstood what I've been reading. The echo commands next to where I'm trying to write assignments are just to test their (in)efficacy, and would be removed from a working script/.sh file. Also, the $JOB_NAME variable in the last line is set to be whatever follows the "#$ -N " part.

In case it is unclear, I'd hope to be able to write something like:

>> qsub file.sh -q short -n name -j "tar -xzf tarfile.tar.gz"
as a simple example.

Any help would be much appreciated.
 
Old 10-15-2013, 08:20 AM   #2
elucches
Member
 
Registered: Jan 2011
Posts: 92

Rep: Reputation: 9
Hello,
I don't know how to use getopts, but can't you use positional parameters (http://tldp.org/LDP/abs/html/othertypesv.html)?
Best regards,
Esteban
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash Script passing arguments dimitriauxio Linux - Newbie 8 09-16-2013 10:19 AM
Passing arguments to shell script like perl script get-opts somupl86 Linux - Newbie 2 12-03-2010 12:14 AM
[SOLVED] passing commands as arguments to functions in bash script mastahyeti Linux - General 3 05-31-2010 07:19 PM
Passing command line arguments through getopts and long options neville310 Programming 3 04-16-2007 07:38 AM
Passing arguments to a shell script subu_s Programming 3 09-02-2005 06:13 AM


All times are GMT -5. The time now is 08:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration