![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| sed remove last 10 characters of a line start from 3rd line | minifish | Shell Programming and Scripting | 7 | 03-26-2008 04:42 PM |
| please help to parse the line | ajaya | Shell Programming and Scripting | 1 | 05-11-2006 02:15 AM |
| please help to parse the line | ajaya | Shell Programming and Scripting | 1 | 05-10-2006 10:11 AM |
| Remove header(first line) and trailer(last line) in ANY given file | madhunk | Shell Programming and Scripting | 2 | 03-13-2006 03:36 PM |
| How to parse a line? | edefoe | Shell Programming and Scripting | 2 | 12-22-2005 06:23 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Aloha! I have just over 1k of users that have permissions that they shouldn't under our system. I need to parse a provided list of usernames, check their permissions file, and strip the permissions that they are not allowed to have. If upon the permissions strip they are left with no permissions, I need have a basic permissions line added to their permission file. I am creating this script so our helpdesk guys can use it later because I can see something similar happening again.
Everything on the following script works correctly unless the user has no permissions left. The sed statement will display the correct insertion but will not overwrite the file. I have also tried piping it to cat and then redirect to the file but that just appends....Please Help!! ![]() Oh! BTW this is in Korn shell under AIX 5.3 Also FYI permission lines are always first in the file and they are the only lines that start with numerals. Code:
echo "Where is the user Listing?"
read usrList
usrName=""
fChar=""
while [ 1 ]
do
read usrName || break
sudo sed -e '/APCLERK/d' /home/$usrName/.facet | cat >> /home/testdir/$usrName
fChar=`head -c 1 /home/testdir/$usrName`
if [[ $fChar != [0-9] ]]
then
sudo sed -f /home/testdir/sedInqIns.sed /home/testdir/$usrName > /home/testdir/$usrName
fi
done < $usrList
Code:
1,1{
i\
1 /PRISM/SD-START "INQUIRY~ ; ; ; ;Y; ; ;0000; ; ;Y; ; ; ; ~~"
}
On execution of this script the users that have no permissions are left with a completely blank file (there should be other settings in the file besides permissions). The users that have other permissions are fine. Any help will be greatly appreciated. Mahalo!! ![]() Last edited by Malumake; 10-23-2007 at 09:17 PM.. Reason: Additional Information |
|
||||
|
I suspect the problem to be the following:
After changing the file /home/$usrName/.facet and writing the results to /home/testdir/$usrName (so far ok) you try to modify this file writing back to it immediately. This is FORBITTEN! Something like sed 's/this/that' file > file.new works, but sed 's/this/that' file > file won't. The reason is: sed will read the first line of the input file (which is "file"), apply any rules that might be applicable and then write the result (the changed or not changed line) to <stdout>. This <stdout> is at this moment pointing to "file" and this is why after the first line the file will contain nothing more than exactly that first line - so sed encounters the EOF and thinks it is finished. In the first example it is not writing back to its input file but some other file "file.new", which is why there is no problem. There is another (perhaps minor) detail i found: You read from keyboard a variable "usrList" and do nothing with it. Why? bakunin |
|
||||
|
Clarification
Believe it or not usrList actually feeds line by line into the do loop.
So, what I'm getting, is that in order for this to work correctly, I need to feed the intial sed statement to a temp file and then have the second sed use the temp back into the original? ![]() |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|