hi I am new to shell programming.....my question is while running one of my shell program it stops in between to accept input from the user and proceeds furthur after giving input....I want to know whether I can set this input through some files so that the shell acript reads the input from the file and will not prompt the user to input the required data...the input is a text...is there any other possibilities using pipes....
Yes, it will automatically take the input from the input file. It's not telling the program to do so, the shell automatically feeds the file into it's input when it creates the process. You can add that to the end of your script, if that's what you wish the script to do. You can even feed the output of one program into the input of another with pipes:
Have you guys anyone worked on CA workload, i have rqmnt that UNIX script should accept the parameter passed through the CA workload and run the process. To explain in the detail CA workload will tell which files is being placed on the server if file1 is placed it needs to process file1 and if file2 is placed it has to process it and so on. Any help would be appreciated.
Here is a sample script I use to rsh commands (I know I should be using SSH instead) to multiple hosts. The hosts to be used and the command to be sent is received from the command line:
#!/bin/ksh
. /usr/sample/etc/unixadm.env #Get host list variables
function printusage {
echo "Usage: checkhosts.ksh [npsu] -c command"
echo " n: AIX non-production"
echo " p: AIX production"
echo " s: SUN production"
echo " u: SUN non-production"
}
while getopts ":npsuc:" opt
do
case $opt in
c) cOmmand="$OPTARG" ;;
n) HOSTS=$AIXNP ;;
p) HOSTS="$AIXPROD $HOSTS" ;;
s) HOSTS="$SUNPROD $HOSTS" ;;
u) HOSTS="$HOSTS $SUNNP" ;;
?) printusage
exit 1;;
esac
done
if [[ -z $cOmmand || -z $HOSTS ]]; then #Check to make sure that there are hosts and a command to use
printusage
exit 2
fi
if ! echo $cOmmand | grep [a-zA-Z]; then #Another validity test
echo "invalid command: $cOmmand"
printusage
exit 2
fi
for i in $HOSTS; do
echo "===== $i ====="
if echo $i | grep -qiE "dev|qa|test"; then
i=$i.qadomain.com
fi
rsh $i $cOmmand
done
On the getopts line:
Having a colon first means that we will process our own errors
Each letter listed is a valid switch
The colon after the c means that a value should accompany the switch on the command line
Thanks for you script. Can you provide me the sample script which should accept only one parameter send through the command line. Also i need to check the argument for following condition
if $arg1 = 'ABC'
concatenate 'ABC' to filename
else
if $arg1 = 'DEF'
concatenate 'DEF' to filename
end-if