Sponsored Content
Top Forums Shell Programming and Scripting Reading ls -l output line by line awk the user name and su user to run commands Post 302874255 by Don Cragun on Thursday 14th of November 2013 02:37:17 PM
Old 11-14-2013
Quote:
Originally Posted by zubairom
Don,

Please see below the complete do while loop

Code:
 
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:
Code:
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

can be replaced by:
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

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

reading ps command's output line by line

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)
Discussion started by: s. murat
5 Replies

2. Shell Programming and Scripting

How a normal user run a script including root privileaged commands

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)
Discussion started by: initin
7 Replies

3. Shell Programming and Scripting

reading a file inside awk and processing line by line

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)
Discussion started by: Anteus
6 Replies

4. Shell Programming and Scripting

[Solved] Problem in reading a file line by line till it reaches a white line

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)
Discussion started by: hakermania
3 Replies

5. Shell Programming and Scripting

How to take input from the user from the command line and execute commands basedon that?

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)
Discussion started by: muraliinfy04
11 Replies

6. Shell Programming and Scripting

how to run a command line with another user without prompts for password

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)
Discussion started by: esolve
1 Replies

7. Shell Programming and Scripting

Script to run commands as root user

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)
Discussion started by: Siddheshk
2 Replies

8. AIX

List of AIX commands that can be run by ROOT user ONLY

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)
Discussion started by: prvnrk
5 Replies

9. HP-UX

How capture all user command line output?

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)
Discussion started by: amvhd
6 Replies

10. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies
echo(1B)					     SunOS/BSD Compatibility Package Commands						  echo(1B)

NAME
echo - echo arguments to standard output SYNOPSIS
/usr/ucb/echo [-n] [argument] DESCRIPTION
echo writes its arguments, separated by BLANKs and terminated by a NEWLINE, to the standard output. echo is useful for producing diagnostics in command files and for sending known data into a pipe, and for displaying the contents of envi- ronment variables. For example, you can use echo to determine how many subdirectories below the root directory (/) is your current directory, as follows: o echo your current-working-directory's full pathname o pipe the output through tr to translate the path's embedded slash-characters into space-characters o pipe that output through wc -w for a count of the names in your path. example% /usr/bin/echo "echo $PWD | tr '/' ' ' | wc -w" See tr(1) and wc(1) for their functionality. The shells csh(1), ksh(1), and sh(1), each have an echo built-in command, which, by default, will have precedence, and will be invoked if the user calls echo without a full pathname. /usr/ucb/echo and csh's echo() have an -n option, but do not understand back-slashed escape characters. sh's echo(), ksh's echo(), and /usr/bin/echo, on the other hand, understand the black-slashed escape characters, and ksh's echo() also understands a as the audible bell character; however, these commands do not have an -n option. OPTIONS
-n Do not add the NEWLINE to the output. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWscpu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), echo(1), ksh(1), sh(1), tr(1), wc(1), attributes(5) NOTES
The -n option is a transition aid for BSD applications, and may not be supported in future releases. SunOS 5.11 3 Aug 1994 echo(1B)
All times are GMT -4. The time now is 04:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy