shell script to execute multiple informatica work flows - shell
I am relatively new to shell scripting and UNIX. I am using a Solaris box and the problem is that
we have a shell script called strtwrfl.sh which takes a parameter as the workflow name and starts the workflow, e.g. ./strtwrfl.sh ABC where ABC is the workflow name.
I have to run over 200 of such workflows, each workflow is dependent on the successful completion of the previous workflow, i.e. if there are 2 workflows ABC and BCD, strtwrfl.sh BCD will be successful only if strtwrfl.sh ABC successfully executed.
Each workflow takes different time to execute successfully.
I have to write a single shell script such that those 200+ informatica workflows must (I dont mind manually entering those workflows into the script) execute one after another, and if one fails the script should halt displaying which workflow failed.
Since this is a production environment I will not be able to share strtwrfl.sh here.
I am not exactly sure I understand your question correctly, but if all you want to do is call a script numerous times in a row with a different parameter and die if an execution fails, you can do something like this:
meta_strtwrfl.sh:
#!/bin/sh
script="./strtwrt.sh"
workflows="
ABC
BCD
CDE
"
for workflow in ${workflows}; do
"${script}" "${workflow}" || { echo "$0: workflow '${workflow}' failed!"; exit 1; }
done
echo "$0: all workflows finished successfully!"
Change script="./strtwrt.sh" to reflect the path to your strtwrt.sh script and change workflows accordingly. I don't know which standard shell you have on your solaris system, so we don't use an array for the workflow variable, which means that your workflow names cannot have spaces in them this way.
Example runs:
$ ./meta_strtwrfl.sh
./meta_strtwrfl.sh: all workflows finished successfully!
$ ./meta_strtwrfl.sh
./meta_strtwrfl.sh: workflow 'ABC' failed!
Shouldnt this be really straightforward ... enter each of these entries on one row.. one after other..
./strtwrfl.sh ABC
./strtwrfl.sh ABC1
./strtwrfl.sh ABC2
..
..
..
and so on..
That would be bare bones..
You can then improvise this by putting in error handling..
or do you want to achieve something different ? which I am not able to catch from the question description ?
<<'notrequired'
wfrunid=`pmcmd getworkflowdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -u ${USER_NAME} -p ${PASSWORD} -usd ${USD} -f ${folder_name} -rin ${RUN_INSTANCE} ${workflow_name} | grep "Workflow run id" | awk -F"[" '{print $2}' | awk -F"]" '{print $1}'`
cur_wf_status=`pmcmd getworkflowdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -u ${USER_NAME} -p ${PASSWORD} -usd ${USD} -f ${folder_name} -rin ${RUN_INSTANCE} ${workflow_name} | grep "Workflow run status" | awk -F"[" '{print $2}' | awk -F"]" '{print $1}'`
if [ "${cur_wf_status}" == "Suspended" ]
then
echo "Workflow $workflow_name Status :${cur_wf_status}"
echo "Workflow $workflow_name Runid :${wfrunid}"
echo " "
echo "######################################## Running workflow in Re-START mode start ################################"
echo "#################################################################################################################"
echo "#################################################################################################################"
pmcmd recoverworkflow -sv ${INTEG_SERVICE} -d ${DOMAIN} -u ${USER_NAME} -p ${PASSWORD} -usd ${USD} -f ${folder_name} -paramfile ${param_file} -rin ${RUN_INSTANCE} -wfrunid ${wfrunid} ${workflow_name}
if [ $? -ne 0 ]
then
echo "################################################# END OF LOG ####################################################"
exit 1
fi
while (true)
do
rec_wf_status=`pmcmd getworkflowdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -u ${USER_NAME} -p ${PASSWORD} -usd ${USD} -f ${folder_name} -rin ${RUN_INSTANCE} ${workflow_name} | grep "Workflow run status" | awk -F"[" '{print $2}' | awk -F"]" '{print $1}'`
rec_wf_log_name=`pmcmd getworkflowdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -u ${USER_NAME} -p ${PASSWORD} -usd ${USD} -f ${folder_name} -rin ${RUN_INSTANCE} ${workflow_name} | grep "Workflow log file" | awk -F"[" '{print $2}' | awk -F"]" '{print $1}'`
case "${rec_wf_status}" in
("Suspended"|"Failed"|"Aborted"|"Stopped") sleep 10
rec_wf_error_start=`pmcmd getworkflowdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -u ${USER_NAME} -p ${PASSWORD} -usd ${USD} -f ${folder_name} -rin ${RUN_INSTANCE} ${workflow_name} | sed -n '/Workflow run error message: /=' | sed -n '$p' 2> /dev/null`
rec_w_error_end=`pmcmd getworkflowdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -usd ${USD} -u ${USER_NAME} -p ${PASSWORD} -f ${folder_name} -rin ${RUN_INSTANCE} ${workflow_name} | sed -n '/Start time: /=' | sed -n '$p' 2> /dev/null`
rec_wf_error_end=`expr $rec_w_error_end - 1 2>/dev/null`
rec_wf_error=`pmcmd getworkflowdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -usd ${USD} -u ${USER_NAME} -p ${PASSWORD} -f ${folder_name} -rin ${RUN_INSTANCE} ${workflow_name} | sed -n "$rec_wf_error_start,$rec_wf_error_end p" 2> /dev/null`
rec_task_name=`echo ${wf_error} | sed 's/\(^.*task instance\)\(.*\)\(].*$\)/\2/' | awk -F"[" '{print $2}' | awk -F"]" '{print $1}'`
rec_task_type=`pmcmd gettaskdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -u ${USER_NAME} -p ${PASSWORD} -usd ${USD} -f ${folder_name} -rin ${RUN_INSTANCE} -w ${workflow_name} ${rec_task_name} | grep "Task type:" | awk -F"[" '{print $2}' | awk -F"]" '{print $1}'`
rec_task_error_start=`pmcmd gettaskdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -usd ${USD} -u ${USER_NAME} -p ${PASSWORD} -f ${folder_name} -rin ${RUN_INSTANCE} -w ${workflow_name} ${rec_task_name} | sed -n '/Task run error message: /=' | sed -n '$p' 2>/dev/null`
rec_error_end=`pmcmd gettaskdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -usd ${USD} -u ${USER_NAME} -p ${PASSWORD} -f ${folder_name} -rin ${RUN_INSTANCE} -w ${workflow_name} ${rec_task_name} | sed -n '/Integration Service: /=' | sed -n '$p' 2>/dev/null`
rec_task_error_end=`expr $rec_error_end - 1 2> /dev/null`
rec_task_error=`pmcmd gettaskdetails -sv ${INTEG_SERVICE} -d ${DOMAIN} -usd ${USD} -u ${USER_NAME} -p ${PASSWORD} -f ${folder_name} -rin ${RUN_INSTANCE} -w ${workflow_name} ${rec_task_name} | sed -n "${rec_task_error_start},${rec_task_error_end} p" 2> /dev/null`
print_error=`echo "Task ${rec_task_name} Failed"`
case "${rec_task_type}" in
("Session") print_error=`echo "${rec_task_name} ${rec_task_error}"`
esac
esac
case "$rec_wf_status" in
"Suspended") echo " "
echo "Workflow Status : ${rec_wf_status}"
echo " "
echo "################################################ WORKFLOW ERROR #################################################"
echo " "
echo "WORKFLOW ${rec_wf_error}"
echo " "
echo "################################################# TASK ERROR ####################################################"
echo " "
echo "Task Type: ${rec_task_type}"
echo " "
echo "${print_error}"
echo " "
execution_stop_time=`date "+%d-%m-%Y-%T"`
echo "Execution Stop Time : $execution_stop_time"
echo " "
echo "################################################# END OF LOG ####################################################"
exit 1
;;
"Succeeded") echo " "
echo "Workflow Status : ${rec_wf_status}"
echo " "
echo "Workflow Run Successfully Completed"
echo " "
execution_stop_time=`date "+%d-%m-%Y-%T"`
echo "Execution Stop Time : $execution_stop_time"
echo " "
echo "################################################# END OF LOG ####################################################"
exit 0
;;
"Aborted") echo " "
echo "Workflow Status : ${rec_wf_status}"
echo " "
echo "################################################ WORKFLOW ERROR #################################################"
echo " "
echo "WORKFLOW ${rec_wf_error}"
echo " "
echo "################################################# TASK ERROR ####################################################"
echo "Task Type: ${rec_task_type}"
echo " "
echo " "
echo "${print_error}"
echo " "
execution_stop_time=`date "+%d-%m-%Y-%T"`
echo "Execution Stop Time : $execution_stop_time"
echo " "
echo "################################################# END OF LOG ####################################################"
exit 1
;;
"Failed") echo " "
echo "Workflow Status : ${rec_wf_status}"
echo " "
echo "################################################ WORKFLOW ERROR #################################################"
echo " "
echo "WORKFLOW ${rec_wf_error}"
echo " "
echo "################################################# TASK ERROR ####################################################"
echo "Task Type: ${rec_task_type}"
echo " "
echo " "
echo "${print_error}"
echo " "
execution_stop_time=`date "+%d-%m-%Y-%T"`
echo "Execution Stop Time : $execution_stop_time"
echo " "
echo "################################################# END OF LOG ####################################################"
exit 1
;;
"Stopped") echo " "
echo "Workflow Status : ${rec_wf_status}"
echo " "
echo "################################################ WORKFLOW ERROR #################################################"
echo " "
echo "WORKFLOW ${rec_wf_error}"
echo " "
echo "################################################# TASK ERROR ####################################################"
echo "Task Type: ${rec_task_type}"
echo " "
echo " "
echo "${print_error}"
echo " "
execution_stop_time=`date "+%d-%m-%Y-%T"`
echo "Execution Stop Time : $execution_stop_time"
echo " "
echo "################################################# END OF LOG ####################################################"
exit 1
;;
esac
done
else
notrequired
Related
Bash Curl Loop Repeation
I have this question, why my context in file is not being submit properly from bash script, I just want to post my context in file to server via my parameters. Error: My complete directory listings get posted into server. #!/bin/bash rm cookiestore.txt rm output.txt echo -e "" echo -e "[-] Input Setting " echo -ne "[+] Enter Host : " read Host echo -e "[?] Obtaining Cookie " curl --silent --cookie-jar cookiestore.txt $Host > /dev/null echo -ne "[+] Enter Parameters : " read Parameters echo -ne "[+] Enter File Path : " read Filepath echo -e "" echo -e "[-] Performing Request " echo -ne "[?] Checking Response URL : " curl -sI $Host -w '%{response_code}%{redirect_url}\n' -o /dev/null echo -ne "[?] Final Redirected Url : " curl -Ls $Host -o /dev/null -w '%{url_effective}' echo -e "" echo -e "" echo -e "[-] Posting " echo -e "[+] Output file : output.txt" echo -e "" while read query do content=$(curl -L -X POST $Host --data "{$Parameters${query}}") echo $query echo $content >> output.txt done < query.txt echo -e "" echo -e "[-] Finished " echo -e ""
Bash assistance recursively grepping directory using a file
I have a txt file (which often gets updated) called hitlist.txt containing a list of words/strings I want to grep a directory against ... like: # This is just a comment and will not be part of the search * Blah - this is a category foo bar sibilance # A new category * Meh - another category snakefish sex panther My list is typically > 100 strings, and each is on its own line. Today, because of a deadline, I simply went through the list and executed the following command for each word: find -iname "*" -type f -print0 | xargs -0 -HniI "foo" >> results.txt As indicated in the command above, I am interested in the file path and name, as well as the line the contains the matched text. There are multiple categories list in the file (denoted by *) and I would like to be able to run my script against one, more, or all categories. I would also like to be able to turn off the -i flag (case sensitivity) as an option. I have a script that recursively finds/lists all files in a directory, and the command I have been using above. Lastly the hitlist format can be changed completely if necessary.
Setup a ghl() (grep hitlist) shell function to do the work, (depends on GNU grep's -o switch, plus a little sed loop), the output is a list of words from hitlist.txt (or <filename>): # usage ghl <glob> <filename> ghl() { grep -o '\* '"$1"' -' "$2" | grep -o '[[:alpha:]]*' | \ while read x ; do \ sed -n '/\* '"$1"'/{:show ;n;/^[^ ]/{p;b show;}}' "$2" ; \ done ; } Pipe the word list output of ghl with an ".*ah" wildcard, (which matches the Blah category), into grep -f -, plus some ad hoc bash process substitution to generate input text: ghl '.*ah' hitlist.txt | grep -i -f - <(echo bar) <(echo foo) <(echo Foo) Output: /dev/fd/63:bar /dev/fd/62:foo /dev/fd/61:Foo The 2nd grep above can be passed switches as desired, (see man grep). Example, the same thing, but case sensitive, (i.e. remove the -i switch): ghl '.*ah' hitlist.txt | grep -f - <(echo bar) <(echo foo) <(echo Foo) Output, (note missing uppercase item): /dev/fd/63:bar /dev/fd/62:foo Since grep already has options to handle recursive searches, the rest is only a matter of adding switches as required.
Your question is extremely vague, but I'm imagining this is more or less what you are looking for. awk -v cat='Blah|Meh' 'NR==FNR && /^#/ { next } # Skip comments NR==FNR && /^\*/ { if ($0~cat) c=1; else c=0; next } NR==FNR { if(c) a[$0]=1; next } lower($0) in a { print FILENAME ":" FNR ":" $0 }' Hits.txt files to search Figuring out how to selectively disable lower() and rigging it to read a list of file names other than Hits.txt from find should be fairly obvious.
This is what I ended up with: hitlist format: # MEH never,going,to give,you up # blah word to,your,mother Script: # Set defaults OUTPUT_FILE="hits.txt" HITLIST_FILE="hitlist.txt" # Hold on to the args ARGLIST=($*) # Declare any functiions help () { echo "--------------------------------- Luffa --------------------------------" echo "Usage: luffa.sh [DIRTOSCRUB]" echo "" echo "Searches DIRTOSCRUB for category specific words in $HITLIST_FILE." echo "" echo "EXAMPLE: luffa.sh dirtoscrub" echo "" echo "--help display this help and exit" echo "--version display version information and exit" } version () { echo "luffa.sh v1.0" } process () { if [ ${#FILEARG} -lt 1 ] # check for proper number of args then echo "ERROR: Specify directory to be searched." help exit 1 else SEARCH_DIR=${ARGLIST[0]} fi echo "" echo "--------------------------------------------------------- Luffa ---------------------------------------------------" | tee -a "$OUTPUT_FILE" echo "search command: find [DIRTOSCRUB] -type f -print0 | xargs -0 grep -HniI --color=always $word | tee -a ../hits.txt | more" | tee -a "$OUTPUT_FILE" echo echo " .,,:::::." | tee -a "$OUTPUT_FILE" echo " .,,::::~:::::.." | tee -a "$OUTPUT_FILE" echo " ,,::::~~~~~~::~~:::." | tee -a "$OUTPUT_FILE" echo " ,:,:~:~~~~~~~~~~~~~~::." | tee -a "$OUTPUT_FILE" echo " ,,:::~:~~~~~~~~~~~~~~~~~~," | tee -a "$OUTPUT_FILE" echo " .,,::::~~~~~~~~~~~~~~~~~~~~~~::" | tee -a "$OUTPUT_FILE" echo " .,::~:~~~~~=~~~~=~~~~~~~~~~~=~~~~." | tee -a "$OUTPUT_FILE" echo " ,::::~~:~~~=~~~~~~~~=~~=~~~===~~~~~~." | tee -a "$OUTPUT_FILE" echo " ..:::~~~~=~~=~~~~~~=~~~~=~~===~~==~~~~~~," | tee -a "$OUTPUT_FILE" echo " .,:::~~~~~~~~~~~~~~~~=~=~~~=~====~===~~~~~~~." | tee -a "$OUTPUT_FILE" echo " .,::~~~~~~~~~~~~~~=~=~~~~~=~======~=~~~~=~=~~~:" | tee -a "$OUTPUT_FILE" echo " ..,::~:~~~~~~=~~~=~~~~~~~~=~====+======~===~~~~~~~." | tee -a "$OUTPUT_FILE" echo " ..,:,:~~~~~~=~::~~=~=~~~=~~=~=~=~======~~~==~~~~~~::." | tee -a "$OUTPUT_FILE" echo " ,,.::~:=~~~~~~~~~~~~=~=~===~~~====+==~=====~~~~~::,." | tee -a "$OUTPUT_FILE" echo " ,,,,:I++=:~==~=~~~~~~=~:==~=~+~====~=~===~~~~:~::,:" | tee -a "$OUTPUT_FILE" echo " .,:+++?77+?=~~~~=~~=~=~~=~~+=~+~~+====~=~~~:::::,::," | tee -a "$OUTPUT_FILE" echo " ..++++?++?II?=~~=~~~=~~~====~===~=====~~~:~::::::::,." | tee -a "$OUTPUT_FILE" echo " ..=++?++++++???7+~~~~~~~~+~=~=====~~~~~~~~~::::~:::,,.." | tee -a "$OUTPUT_FILE" echo " .=+++++++++++++++===:~~=~==+~~=~=~~:~~=~:~:::~::::,,.." | tee -a "$OUTPUT_FILE" echo " .++++++?++++++?++=?~:~~~~===~==~==~~~~~:::::::::,,,..." | tee -a "$OUTPUT_FILE" echo " ..=?+++++??+++++++===~::~~~~~~=~~~~~~:~~:::::,:,,,,,." | tee -a "$OUTPUT_FILE" echo " ...=+?+++++++++=====~:,::,~:::~~~~~:~~~~::::~::::,,,,.." | tee -a "$OUTPUT_FILE" echo " .=+++++++++++===~==::::,::~~,,,::~~~~~~::::::~:,:,,.." | tee -a "$OUTPUT_FILE" echo " ..++++++++++=+===~,.,,:::,:~~~~~,.,:~:~::::::,::,:,.." | tee -a "$OUTPUT_FILE" echo " ...++?++++++++=+=~~. ..,,,,,:,~,::~,:::,:,:,~::::,,.." | tee -a "$OUTPUT_FILE" echo " .++++++++?++====~. ...,,:,~::~=::,::,:,:::,,,,.." | tee -a "$OUTPUT_FILE" echo ".++?+++++?++++==~.. .,.:,,:::~,:,,,:::::,,,." | tee -a "$OUTPUT_FILE" echo "++++++?+???==~=. ...,::~~~:,,:,:::,,." | tee -a "$OUTPUT_FILE" echo "?+++?????+==~. ..,,,,::,:,,,,,." | tee -a "$OUTPUT_FILE" echo "+?+++??+==~. ..,,,,,,,,." | tee -a "$OUTPUT_FILE" echo "+I???+==~. ..,,.." | tee -a "$OUTPUT_FILE" echo "??++==~." | tee -a "$OUTPUT_FILE" echo "+===~." | tee -a "$OUTPUT_FILE" echo "+=~." | tee -a "$OUTPUT_FILE" echo "~" | tee -a "$OUTPUT_FILE" echo "--------------------------------------------------------------------------------------------------------------------------" | tee -a "$OUTPUT_FILE" echo "" | tee -a "$OUTPUT_FILE" # Loop through hitlist while read -re hitList || [[ -n "$hitList" ]] do # If first character is "#" it's a comment, or line is blank, skip if [ "$(echo $hitListWords | head -c 1)" != "#" ]; then if [ ! -z "$hitListWords" -a "$hitListWords" != "" ]; then # Parse comma delimited category specific hitlist IFS=',' read -ra categoryWords <<< "$hitListWords" # Search for occurences/hits for the hitList word for categoryWord in "${categoryWords[#]}"; do echo "---------------------------------------------------" | tee -a "$OUTPUT_FILE" echo "$category - \"$categoryWord"\" | tee -a "$OUTPUT_FILE" echo "---------------------------------------------------" | tee -a "$OUTPUT_FILE" eval 'find "$SEARCH_DIR" -type f -print0 | xargs -0 grep -HniI "$categoryWord" >> "$OUTPUT_FILE"' eval 'find "$SEARCH_DIR" -type f -print0 | xargs -0 grep -HniI --color=always "$categoryWord" | more' echo "" | tee -a "$OUTPUT_FILE" done fi else category="$(echo "$hitListWords" | cut -d "#" -f 2)" fi done < "$HITLIST_FILE" exit $? } # Process the options while [[ "${ARGLIST[0]}" == -* ]]; do OPTION="${ARGLIST[0]}" NUM_OPTS=1; case $OPTION in --version) version exit 0 ;; --help) help exit 0 ;; *) help exit 1 ;; esac ARGLIST=(${ARGLIST[#]:$NUM_OPTS}) done FILEARG=${ARGLIST[#]} process
hide output with errors from stdout
need hide error from the script for s in $s_list; do if [ "${s}" = "test" ]; then db_status=$(mysql -h localhost -P 3306 -u test -ptest -e "show create database test;" | awk {'print $1'} | tail -n 1 ) db_status_error=$(mysql -h localhost -P 3306 -u test -ptest -e "show create database test;" 2>&1 | awk {'print $1'} | tail -n 1 ) # echo $db_status_error if [ "$db_status" == "test" ]; then echo "Database exist, need wait..." sleep 2; elif [ "$db_status_error" == "ERROR" ] < /dev/null > /dev/null 2>&1 ; then echo "Database does not exist" sleep 2; exit 0 fi fi done result is ERROR 1049 (42000) at line 1: Unknown database 'test' Database does not exist i need just line with Database does not exist
You need to redirect stderr to /dev/null when you set db_status: db_status=$(mysql -h localhost -P 3306 -u test -ptest -e "show create database test;" 2> /dev/null | awk {'print $1'} | tail -n 1 )
wget bash function without messy output
I am learning to customize wget in a bash function and having trouble. I would like to display Downloading (file):% instead of the messy output of wget. The function below seems close I am having trouble calling it for my specific needs. For example, my standard wget is: cd 'C:\Users\cmccabe\Desktop\wget' wget -O getCSV.txt http://xxx.xx.xxx.xxx/data/getCSV.csv and that downloads the .csv as a .txt in the directory specified with all the messy wget output. This function seems like it will do more-or-less what I need, but I can not seem to get it to function correctly using my data. Below is what I have tried. Thank you :). #!/bin/bash download() { local url=$1 wget -O getCSV.txt http://xxx.xx.xxx.xxx/data/getCSV.csv local destin=$2 'C:\Users\cmccabe\Desktop\wget' echo -n " " if [ "$destin" ]; then wget --progress=dot "$url" -O "$destin" 2>&1 | grep --line-buffered "%" | \ sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", $2)}' else wget --progress=dot "$url" 2>&1 | grep --line-buffered "%" | \ sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", $2)}' fi echo -ne "\b\b\b\b" echo " DONE" } EDITED CODE #!/bin/bash download () { url=http://xxx.xx.xxx.xxx/data/getCSV.csv destin='C:\Users\cmccabe\Desktop\wget' echo -n " " if [ "$destin" ]; then wget -O getCSV.txt --progress=dot "$url" -O "$destin" 2>&1 | grep --line-buffered "%" | \ sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", $2)}' else wget -O getCSV.txt --progress=dot $url 2>&1 | grep --line-buffered "%" | \ sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", $2)}' fi echo -ne "\b\b\b\b" echo " DONE" menu } menu() { while true do printf "\n Welcome to NGS menu (v1), please make a selection from the MENU \n ==================================\n\n \t 1 Patient QC\n ==================================\n\n" printf "\t Your choice: "; read menu_choice case "$menu_choice" in 1) patient ;; *) printf "\n Invalid choice."; sleep 2 ;; esac done }
Syntax error: “(” unexpected (expecting “fi”)
filein="users.csv" IFS=$'\n' if [ ! -f "$filein" ] then echo "Cannot find file $filein" else #... groups=(`cut -d: -f 6 "$filein" | sed 's/ //'`) fullnames=(`cut -d: -f 1 "$filein"`) userid=(`cut -d: -f 2 "$filein"`) usernames=(`cut -d: -f 1 "$filein" | tr [A-Z] [a-z] | awk '{print substr($1,1,1) $2}'`) #... for group in ${groups[*]} do grep -q "^$group" /etc/group ; let x=$? if [ $x -eq 1 ] then groupadd "$group" fi done #... x=0 created=0 for user in ${usernames[*]} do useradd -n -c ${fullnames[$x]} -g "${groups[$x]}" $user 2> /dev/null if [ $? -eq 0 ] then let created=$created+1 fi #... echo "${userid[$x]}" | passwd --stdin "$user" > /dev/null #... echo "Welcome! Your account has been created. Your username is $user and temporary password is \"$password\" without the quotes." | mail -s "New Account for $user" -b root $user x=$x+1 echo -n "..." sleep .25 done sleep .25 echo " " echo "Complete. $created accounts have been created." fi
I'm guessing the problem is that you're trying to capture command output in arrays without actually using command substitution. You want something like this: groups=( $( cut... ) ) Note the extra set of parentheses with $ in front of the inner set.