Two for loops in ksh script only one not executing
Hello,
I have two "for loops" in my script and the second one is not executing the way i want.
Script:
Code:
#!/bin/ksh
IFS=' '
printf "Enter Account name[s]: "
read A B C D E F G H I J K L M N O
for i in ${A} ${B} ${C} ${D} ${E} ${F} ${G} ${H} ${I} ${J} ${K} ${L} ${M} ${N} ${O}; do
# Check disk space
echo
df -g /home/$i
done
echo
# Show the parent directory and pid
for x in `ps -ef | grep BLANKET.CANCEL | grep -v grep | awk '{print $2}'`;do procwdx $x;done
Script output:
Code:
Enter Account name[s]: MUSE SPORTS
Filesystem GB blocks Free %Used Iused %Iused Mounted on
/dev/fslv01 6.00 1.15 81% 90760 25% /home2
Filesystem GB blocks Free %Used Iused %Iused Mounted on
/dev/hd1 21.75 3.83 83% 208763 18% /home
procwdx : no such process : 15401052
17170584
18481212
23920844
28573800
When I run the second "for loop" out of the script it works fine:
Code:
# for x in `ps -ef | grep BLANKET.CANCEL | grep -v grep | awk '{print $2}'`;do procwdx $x;done
15401052: /home2/MUSE/
17170584: /home/ARTSDEMO/
18481212: /home/ARTS/
23920844: /home/SPORTS/
28573800: /home2/ARENA/
For the first loop, you can read a single variable to hold the account names and set the loop on that:-
Code:
printf "Enter Account name[s]: "
read A
for i in ${A}
do
printf "Working on account ${i}\n"
done
The second loop confuses me a little. Assuming that you are looking for all process, you can slim this down too:-
Code:
ps -ef | grep BLANKET.CANCE[L] | cut -f2 -d" " | while read a x b
do
procwdx $x
done
The a grabs the first item on the line, the x and the b grabs the rest.
The square brackets in the grep part of the line form an expression with only one option, i.e. and L, but it means that you will not match the grep command itself.
It is possible that you code as it stands is getting the process id of the running script. Pop in a simple message at the beginning to see if that matches.:-
ps can have multi-space delimiters, while cut -d" " handles one-space delimiters. [ ] must be within quotes, otherwise the shell matches it against the current directory.
Enough reasons for awk:
Code:
ps -ef | awk '/BLANKET.CANCE[L]/ {print $2}' |
while read x
do
procwdx $x
done
Maybe AIX ps has Posix options? These are more efficient:
I'm having a brain freeze moment. I've created a ksh script in AIX that ssh's to a remote server, executes some commands, and then logs out. All of this is sent to a file. I then have the script cat the file so i can see the output. Even though the cat command is outside of the remote session part;... (5 Replies)
I am trying to call a ksh script from another ksh script.
in the called script , i am doing sum calculation(used typeset etc)
suppose a.ksh is the calling script and b.ksh is the called script .
. b.ksh (used this inside a.ksh)
this execution gives some error like bad number.
but when i... (1 Reply)
It's been a while since I used csh formatting and I am having a little bit of trouble with a few things. Things seem so much easier to execute in Matlab, however I need to do this on the terminal because of the programs I am trying to interact with.
So here's what I want to do: I have a file... (0 Replies)
KSH isn't my strong suit but it's what my company has to offer. I've got a script with two nested loops, a FOR and UNTIL, and that works fine. When I add a CASE into the mix I end up getting "Unexpected 'done' at line xx" errors. Any suggestions on this?
for divi in at ce ci cm co de di fl... (9 Replies)
Hi,
I am in ksh.
below mentioned 3 commands I executed at command prompt & got the expected results.
csh
source csh_infa
<special command>
Now I have to do this in the script in ksh. I entered it as it is.
#!/bin/ksh
csh
source csh_infa
<special command>
Now after... (1 Reply)
Hi,
I'm new to unix scripting.How can i call a script from another script.
I have a.ksh and b.ksh .I have to call b.ksh from a.ksh after it is successfully exceuted.
I tried using
#!/bin/ksh -x in a.ksh and at the end i have used /path/b.ksh
My problem is it is executing only a.ksh.it... (6 Replies)
Hello all,
Here's the scenario:
I've got a script, let's call it script1. This script invokes another script, which we'll call set_env, via the dot "." command, like so:
File:
#!/bin/ksh
#
region_id=DEV
. set_env ${region_id}
and so on. Script set_env sets up an... (2 Replies)
i want to add about 60 printers using a ksh script.
i am having trouble though, i am reading the input from the hosts file and using the lpadmin command to add like so:
lpadmin -p -v /dev/null -m netstandard -o dest=
i want printername and ipaddy to come from the hosts file, i am having... (1 Reply)
Hi all,
I'm developing a system which requires me to run a ksh script from within a cgi script. What sort of syntax will I need to do this, I'm sure it's simple but can't find out how anywhere!
Thanks. (1 Reply)