From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: joe joe Newsgroups: gmane.os.tru64.managers Subject: SUMMARY: insert text into .profile Date: Thu, 20 Feb 2003 13:14:41 -0800 (PST) Sender: tru64-unix-managers-owner@ornl.gov Message-ID: <20030220211441.4253.qmail@web41101.mail.yahoo.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1045775708 18803 80.91.224.249 (20 Feb 2003 21:15:08 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Thu, 20 Feb 2003 21:15:08 +0000 (UTC) Return-path: Original-Received: from sws1.ctd.ornl.gov ([160.91.22.101]) by main.gmane.org with smtp (Exim 3.35 #1 (Debian)) id 18ly1z-0004ri-00 for ; Thu, 20 Feb 2003 22:14:59 +0100 Original-Received: (qmail 13384 invoked by uid 5); 20 Feb 2003 21:14:53 -0000 Original-Followup-To: poster Precedence: bulk Original-Received: (qmail 13351 invoked by uid 49493); 20 Feb 2003 21:14:53 -0000 Original-Received: from daytona5891@yahoo.com by sws1 by uid 49491 with qmail-scanner-1.14 (clamscan: 0.54. spamassassin: 2.50-cvs. Clear:SA:0(1.5/5.0):. Processed in 0.532742 secs); 20 Feb 2003 21:14:53 -0000 Original-Received: from unknown (HELO emroute2.cind.ornl.gov) (128.219.159.41) by 0 with SMTP; 20 Feb 2003 21:14:53 -0000 Original-Received: from emroute2.cind.ornl.gov (LOCALHOST [127.0.0.1]) by emroute2.cind.ornl.gov (PMDF V6.1-1 #30669) with ESMTP id <0HAM00LFDLOK1U@emroute2.cind.ornl.gov> for tru64-unix-managers@sws1.ctd.ornl.gov (ORCPT tru64-unix-managers@ornl.gov) ; Thu, 20 Feb 2003 16:14:52 -0500 (EST) Original-Received: from web41101.mail.yahoo.com (web41101.mail.yahoo.com [66.218.93.17]) by emroute2.cind.ornl.gov (PMDF V6.1-1 #30669) with SMTP id <0HAM00KG8LOHW6@emroute2.cind.ornl.gov> for tru64-unix-managers@sws1.ctd.ornl.gov (ORCPT tru64-unix-managers@ornl.gov) ; Thu, 20 Feb 2003 16:14:42 -0500 (EST) Original-Received: from [199.79.112.101] by web41101.mail.yahoo.com via HTTP; Thu, 20 Feb 2003 13:14:41 -0800 (PST) Original-To: tru64-unix-managers@ornl.gov Xref: main.gmane.org gmane.os.tru64.managers:3399 X-Report-Spam: http://spam.gmane.org/gmane.os.tru64.managers:3399 from daytona5891@yahoo.com (Joe Joe Sheppard) Contents: thanks original email futhur clarification advise received Thanks: Thanks to all to helped!! This is a great list to be on. Appreciation to the following helpers: Alan Davis Trevor Osatchuk Dr. Tim Cutts J.A. Gutierrez Bob Vickers Greg Palmer Mandell Degerness Original Email: Greetings, As a new sys admin, I am in need of some scripting help. I need to change the path in the .profile of all my users from: . /lawson/802/law/system/profile to . /lawson/law/system/profile I could insert the new part, 802/, by hand, but would prefer a quick script. Thanks for any help you can give me. Further Clarification: When I arrived this morning, I was notified that NOT all the /usr/users had to be changed. In addition, linking or changing the /etc/profile was refused. Further complicating things was the fact that my original email was unclear to whether I was the 802 text, or was trying to remove it. I was trying to actually add it. I was able to use a consortium of Trevor's and Mandell's responses to solve the issue. Advice Received From: Alan Davis: perl -pi.bak -e 's///g' file file file ... you could wrap this in a find command : find / -name .profile -exec /bin/perl -pi.bak -e 's/\/802/\/\//g' {} \; Trevor Osatchuk: There are a couple of things you can do here. 1. If all users have the same .profile file you only need to change one and then copy it to all directories. OR 2. If everyone has added their own changes to their .profile files making them all unique, you can do this in two steps from the command line: 1. Run this command, this will substitute all instances of /802 for nothing, eliminating it from the path for every .profile in /usr/users/*/ and make a new .profile file in all of the home directories called .profile.new. This assumes all user home directories are in /usr/users/*. for file in `ls /user/users/*/.profile; do sed 's#/802##' $file > $file.new; done 2. To change the .profile.new files to be the new .profile file do this: for file in `ls /user/users/*/.chhrc; do mv $file.new $file; done This will move the .profile.new files to .profile. I have tested this here on my site and it seems to work. Run the first command and make sure the .profile.new files are in the home directories and that the appropriate change was made. Like I said, this will eliminate ALL instances of /802, so if it show up somewhere else you may have to change the sed command to search for the correct line. If this is the case give it try yourself and if you still need help just email me back. Check out the sed man page and play with the for loop from the command line. You can do some pretty cool stuff without having to write a script! Dr. Tim Cutts: perl -npi -e 's:^\s*\.\s*/lawson/802/law/system/profile:. /lawson/law/system/profile:' Apply that to each user's .profile. If you want to find all the .profile files in users' home directories, you can do something like: foreach hd ( `awk -F: '$3>100 && $1 !~ /nobody/ {print $6}' /etc/passwd | sort -u` ) if ( -f $hd/.profile ) then perl [ perl_command_above ] $hd/.profile endif end but take *great* care. :-) It's probably safest not to change their profiles at all, but just to make a symbolic link from the old location to the new one. J.A. Gutierrez: You could use something similar to this one: --------------------------------------------------------------------------- #!/bin/sh while read user do grep timenet /home/$user/.cshrc ||\ ( ed /home/$user/.cshrc <<- ++ /foreach f/s/)$/ timenet )/ w q ++ ) grep timenet /home/$user/.zlogin ||\ ( ed /home/$user/.zlogin <<- ++ /for f in/s/$/ timenet/ w q ++ ) grep timenet /home/$user/.profile ||\ ( ed /home/$user/.profile <<- ++ /for f in/s/$/ timenet/ w q ++ ) done < u Bob Vickers: Dear Joe Joe, I wrote a script which lets you edit lots of files at once. Downloadmassedit from http://www.cs.rhul.ac.uk/home/bobv/utils/ and type something like massedit /lawson/802/law/system/profile /lawson/law/system/profile */.profile Michael Campbell: Joe.. Could you just "vi" the .profile file and end the misery? Greg Palmer: If ALL your users need the change, why not just remove the old profile, and recreate it as a symbolic link to the new one? BTW--your note said the 802 was the OLD one (from/to) was this right? Your note later said 'I could insert the new part 802/'...? mv /lawson/law/system/profile /lawson/law/system/profile.orig ln -s /lawson/802/law/system/profile /lawson/law/system/profile This points the /lawson/law/system/profile to /lawson/802/law/system/profile Mandell Degerness: This will insert... sed 's/\/lawson\/law\/system\/profile/\/lawson\/802\/law\/system\/profile/g' > .new mv .new __________________________________________________ Do you Yahoo!? Yahoo! Tax Center - forms, calculators, tips, more http://taxes.yahoo.com/