Thanks Made in Germany and Carlos for your input... Now I understand what Carlos meant... Yes echoing the $line works ... That was confusing me as why the why loop goes into the awk subshell...you guys cleared that.
For this script I will use variables as suggested by Don as that is a simpler approach.
regarding the additional checks that you proposed </dev/null work fine but I run into some issues using -f option for su and the 'ticks'... With -f option for su it looks like I can't use -R for chmod(my original script did not have -R for chmod but now I added it) and I get
Code:
-R: 0403-010 A specified flag is not valid for this command.
With the 'ticks' looks like it can't resolve the variable(which is what i thought)
Code:
chmod: /saswork/sastemp/$sas_work_dir: A file or directory in the path name does not exist.
Last edited by Don Cragun; 11-12-2013 at 12:55 PM..
Reason: Switch ICODE tags to CODE tags and remove extraneous spaces.
Thanks Made in Germany and Carlos for your input... Now I understand what Carlos meant... Yes echoing the $line works ... That was confusing me as why the why loop goes into the awk subshell...you guys cleared that.
For this script I will use variables as suggested by Don as that is a simpler approach.
regarding the additional checks that you proposed </dev/null work fine but I run into some issues using -f option for su and the 'ticks'... With -f option for su it looks like I can't use -R for chmod(my original script did not have -R for chmod but now I added it) and I get
Code:
-R: 0403-010 A specified flag is not valid for this command.
With the 'ticks' looks like it can't resolve the variable(which is what i thought)
Code:
chmod: /saswork/sastemp/$sas_work_dir: A file or directory in the path name does not exist.
The error message you showed above should not be printed as a result of using the command:
Code:
</dev/null su $sas_user -fc "whoami; chmod 777 /saswork/sastemp/'$sas_work_dir'"
The double quotes around the string whoami; chmod 777 /saswork/sastemp/'$sas_work_dir' make the single quotes regular characters with no special meaning, so $sas_work_dir should be expanded before su is invoked. Assuming as an example that $sas_work_dir expands to some/dir), the shell should invoke su with a final operand that is the string whoami; chmod 777 /saswork/sastemp/'some/dir' and the shell that su invokes would then remove those single quotes.
Please show us the exact command line that you are using to invoke su.
SCRIPT_DIR=/u/sasp/scripts/purge_clean
SASWORK_LIST_SASWORK=$SCRIPT_DIR/saswork_list_saswork
SASWORK=$1
cd $SASWORK
ls -ltr | egrep -i -v 'total [0-9]+' > $SASWORK_LIST_ALL_BEFORE
egrep -i 'SAS_[0-9a-z]{16}_[0-9a-z]+' $SASWORK_LIST_ALL_BEFORE > $SASWORK_LIST_SASWORK
while read -r x x sas_user x x x x x sas_work_dir
do
# su the owner of each work directory and change permisions to 777 for the work directory
echo $sas_user
echo $sas_work_dir
</dev/null su $sas_user -c "chmod -R 777 /saswork/sastemp/$sas_work_dir" # </dev/null prevents an eventual reading from stdin. Just a safety check
done < $SASWORK_LIST_SASWORK
Thanks
Omer
Last edited by Don Cragun; 11-12-2013 at 03:42 PM..
Reason: Please use CODE tags (not ICODE tags) for multi-line sequences.
Actually you and Don are right.. single quotes within double quotes are not causing any error.
I must have done somethign wrong the first time when I tested and got the error about not finding the directory..I tested again with single quotes around the '$sas_work_dir' and it worked fine thsi time..
SCRIPT_DIR=/u/sasp/scripts/purge_clean
SASWORK_LIST_SASWORK=$SCRIPT_DIR/saswork_list_saswork
SASWORK=$1
cd $SASWORK
ls -ltr | egrep -i -v 'total [0-9]+' > $SASWORK_LIST_ALL_BEFORE
egrep -i 'SAS_[0-9a-z]{16}_[0-9a-z]+' $SASWORK_LIST_ALL_BEFORE > $SASWORK_LIST_SASWORK
while read -r x x sas_user x x x x x sas_work_dir
do
# su the owner of each work directory and change permisions to 777 for the work directory
echo $sas_user
echo $sas_work_dir
</dev/null su $sas_user -c "chmod -R 777 /saswork/sastemp/$sas_work_dir" # </dev/null prevents an eventual reading from stdin. Just a safety check
done < $SASWORK_LIST_SASWORK
Thanks
Omer
Do you use the contents of the files named by $SASWORK_LIST_ALL_BEFORE and $SASWORK_LIST_SASWORK after this loop completes? If $SASWORK_LIST_ALL_BEFORE isn't used after this loop, the first egrep is superfluous and the code:
ls -ltr | egrep -i 'SAS_[0-9a-z]{16}_[0-9a-z]+' > $SASWORK_LIST_SASWORK
If $SASWORK_LIST_SASWORK isn't used after this loop either, then neither file is needed:
Code:
ls -ltr | egrep -i 'SAS_[0-9a-z]{16}_[0-9a-z]+' |
while read -r x x sas_user x x x x x sas_work_dir
do
# su the owner of each work directory and change permisions to 777 for the work directory
echo $sas_user
echo $sas_work_dir
</dev/null su $sas_user -c "chmod -R 777 /saswork/sastemp/$sas_work_dir" # </dev/null prevents an eventual reading from stdin. Just a safety check
done
I actually do use SASWORK_LIST_BEFORE again. The script deletes the orphaned SAS work directories and afterwards it runs sdiff on SASWORK_LIST_BEFORE with SASWORK_LIST_AFTER.
Also another reason why I keep these files temoprarily(deleted at the end of the end of the script) is because I generate a report from these files.
Hi
I want to know how capture all user command line output and save this commands and outputs to text files?
if you have script for this subject please give me.:o
please help me
thank you (6 Replies)
Hello,
I am testing sudo and I want to test it. Can anyone please let me know few commands (of course other than shutdown, reboot etc. as I can't reboot the box) on AIX that can be run by ROOT only.
Thanks
---------- Post updated at 07:43 PM ---------- Previous update was at 07:38 PM... (5 Replies)
Hello I have a script which is working fine so far to generate HTML file. Now i am wondering how do i include a syntax where it can change itself to root user and execute a specific commands as root user.
Please help, Thanks in advance.
-Siddhesh (2 Replies)
Hi, I'm writing a script,
in the script I need to use tcpdump to capture some packets
however it needs root priviledge
my computer is configured by school and I have no real root priviledge
so I can't use sudo on my computer,like
Code:
sudo tcpdump ......
I have to use a limited... (1 Reply)
Hi,
I am using solaris 10 and bash shell.Script execution follows below.Initially it will check whether a directory exists or not if does not exist it will create it.(This I have completed)
Second step:I have four users say user1,user2,user3,user4.Script should prompt for the user id and... (11 Replies)
So, I want to read line-by-line a text file with unknown number of files....
So:
a=1
b=1
while ; do
b=`sed -n '$ap' test`
a=`expr $a + 1`
$here do something with b etc
done
the problem is that sed does not seem to recognise the $a, even when trying
sed -n ' $a p'
So, I cannot read... (3 Replies)
Hi Sorry to multipost. I am opening the new thread because the earlier threads head was misleading to my current doubt.
and i am stuck.
list=`cat /u/Test/programs`;
psg "ServTest" | awk -v listawk=$list '{
cmd_name=($5 ~ /^/)? $9:$8
for(pgmname in listawk)
... (6 Replies)
Dear all
Ihave written a script in Hpux9.0, the ecript is working fine if I run it from root command prompt
But when I am running it thru /etc/profile or /user/.profile and login as a normal user, the owner of the process running the script is the normal user & hence cant run a root privileaged... (7 Replies)
hi;
as a pseudo;
while read psLine
do
myFunc $psLine
done < ps
i don't want to redirect ps command's to a file. in fact, my problem is "how can i
read stdout line by line in bash, sed, awk or any?"
thanks, (5 Replies)