Hi,
I wrote a unix script that will perform differnt tasks on bahalf of number of users. I use "sudo" to run the script. The problem is when I execute the command: su - user -c "xxx " > output_file, I get the system output header frm the su command. Is there a way to get rid of it instdead of... (2 Replies)
Hi, have managed to code a script that has a simple menu so for instance if I run:
this will call a help function that displays the programs help, I have coded this in using a case statement so if: case is h) call the help function
The problem is I don't know how to code in the... (3 Replies)
Hi all,
This is my first ever post to any forum so, dont let this go in vain...........:)
Here is the scenario........
I have logged into the unix where oracle_sid is initialized for some X database in the .profile.
I have a unix script where some sql query which fetches data from X... (3 Replies)
Hi Experts,
I'm trying to write a shell script to stop few things where i have to use another user to execute a command. Otherwise it will not work.
Your help is really appreciated
Thanks, (16 Replies)
Hi,
script1.sh
script2.sh
script3.sh
From above, script1.sh is the main script which is executed from root user, creates installation directory, changing ownership and execution rights etc..etc.. and finally calls scripot2.sh and script3.sh to create the database as well as for post... (1 Reply)
I need a script to change server automatically after performing some operations.
The command for changing server is ssh username@servername . Then a prompt comes to enter a password. Then i need to perform some opertaions on the other server. How can i do this in a script? (1 Reply)
I am writing a korn shell script where i need to switch to root in between and again exit from root to normal user and continue other commands.
Is that possible to switch between these two in the same script? (1 Reply)
Hello
I want to create a script which will require a mandatory value and optional values which can be supplied using switch. If optional values are not supplied, the script will use the default values mentioned in the script.
For example, how we create user in linux systems.
Please... (3 Replies)
HI
in a server we can't login with root user directly but i can login with different user and then i can switch to root user by su command
Requirement
is there anyway where i can write a script without mentioning password in file as mentioning the root password is not the... (3 Replies)
Discussion started by: scriptor
3 Replies
LEARN ABOUT FREEBSD
getopt
GETOPT(1) BSD General Commands Manual GETOPT(1)NAME
getopt -- parse command options
SYNOPSIS
args=`getopt optstring $*` ; errcode=$?; set -- $args
DESCRIPTION
The getopt utility is used to break up options in command lines for easy parsing by shell procedures, and to check for legal options.
Optstring is a string of recognized option letters (see getopt(3)); if a letter is followed by a colon, the option is expected to have an
argument which may or may not be separated from it by white space. The special option '--' is used to delimit the end of the options. The
getopt utility will place '--' in the arguments at the end of the options, or recognize it if used explicitly. The shell arguments ($1 $2
...) are reset so that each option is preceded by a '-' and in its own shell argument; each option argument is also in its own shell argu-
ment.
EXIT STATUS
The getopt utility prints an error message on the standard error output and exits with status > 0 when it encounters an option letter not
included in optstring.
EXAMPLES
The following code fragment shows how one might process the arguments for a command that can take the options -a and -b, and the option -o,
which requires an argument.
args=`getopt abo: $*`
# you should not use `getopt abo: "$@"` since that would parse
# the arguments differently from what the set command below does.
if [ $? -ne 0 ]; then
echo 'Usage: ...'
exit 2
fi
set -- $args
# You cannot use the set command with a backquoted getopt directly,
# since the exit code from getopt would be shadowed by those of set,
# which is zero by definition.
while true; do
case "$1" in
-a|-b)
echo "flag $1 set"; sflags="${1#-}$sflags"
shift
;;
-o)
echo "oarg is '$2'"; oarg="$2"
shift; shift
;;
--)
shift; break
;;
esac
done
echo "single-char flags: '$sflags'"
echo "oarg is '$oarg'"
This code will accept any of the following as equivalent:
cmd -aoarg file file
cmd -a -o arg file file
cmd -oarg -a file file
cmd -a -oarg -- file file
SEE ALSO getopts(1), sh(1), getopt(3)HISTORY
Written by Henry Spencer, working from a Bell Labs manual page. Behavior believed identical to the Bell version. Example changed in FreeBSD
version 3.2 and 4.0.
BUGS
Whatever getopt(3) has.
Arguments containing white space or embedded shell metacharacters generally will not survive intact; this looks easy to fix but is not. Peo-
ple trying to fix getopt or the example in this manpage should check the history of this file in FreeBSD.
The error message for an invalid option is identified as coming from getopt rather than from the shell procedure containing the invocation of
getopt; this again is hard to fix.
The precise best way to use the set command to set the arguments without disrupting the value(s) of shell options varies from one shell ver-
sion to another.
Each shellscript has to carry complex code to parse arguments halfway correctly (like the example presented here). A better getopt-like tool
would move much of the complexity into the tool and keep the client shell scripts simpler.
BSD January 26, 2011 BSD