- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Sed /perl/Awk insert - code into user /home/userna...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-30-2010 08:30 AM
тАО03-30-2010 08:30 AM
I need to create a for or do-while that inserts a section of code into the users .profile
###
Say I have a file /tmp/LOCKINFO
that contains..
if [ -d "/tmp/USERLOCK" ]
then
cat /etc/motd
echo "press any key to continue\n"
read
exit
fi
I want to insert into the top of EACH user profile
Basically I have this working in a couple test
cd /home/groupname/
for file in `find . -name .profile -print`
do
### SOME COMMAND to INSERT CODE above into
Doing this put it at the bottom of the file.
cat /tmp/USERLOCK >> $FILE
I need to some how insert this code or call this from the top?
Any ideas appreciated
Solved! Go to Solution.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-30-2010 08:46 AM
тАО03-30-2010 08:46 AM
Re: Sed /perl/Awk insert - code into user /home/username/.profile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-30-2010 08:48 AM
тАО03-30-2010 08:48 AM
Re: Sed /perl/Awk insert - code into user /home/username/.profile
for example, I /tmp/dist1LOCK exists, then exit. But I have a couple users in this dist1 that I need to allow access, this is why I want to populate user profile.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-30-2010 08:51 AM
тАО03-30-2010 08:51 AM
Re: Sed /perl/Awk insert - code into user /home/username/.profile
cat /etc/motd, where /etc/motd contains your message.
So it looks like your code will work in /etc/profile to me also.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-30-2010 09:10 AM
тАО03-30-2010 09:10 AM
SolutionYou could insert your block of code :
...at the top of the '.profile' beginning after line-1:
# cat .insertattop
#!/usr/bin/perl
use strict;
use warnings;
local $^I = '.old';
my $insert = <<"EOF!"
if [ -d "/tmp/USERLOCK" ]
then
cat /etc/motd
echo "press any key to continue\n"
read
exit
fi
EOF!
;
while (<>) {
print $insert if ( $. == 2 );
print;
}
continue {
close ARGV if eof;
}
1;
...or, at the bottom of the '.profile' as the last block of lines:
# cat .insertatbot
#!/usr/bin/perl
use strict;
use warnings;
local $^I = '.old';
my $insert = <<"EOF!"
if [ -d "/tmp/USERLOCK" ]
then
cat /etc/motd
echo "press any key to continue\n"
read
exit
fi
EOF!
;
while (<>) {
print;
}
continue {
if (eof) {
print $insert;
close ARGV;
}
}
1;
...In *both* cases, run the script and pass one or more filenames as its arguments. In both cases, a backup copy of the original file will be created with a suffix of '.old' and the new file updated in-place.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-30-2010 09:22 AM
тАО03-30-2010 09:22 AM
Re: Sed /perl/Awk insert - code into user /home/username/.profile
And, though I probably don't need to say, you can couple either of the above scripts to a driving 'find()' by doing:
# cd /home/groupname && find . -type f -name .profile -exec /usr/local/bin/insertattop {} +
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-30-2010 09:24 AM
тАО03-30-2010 09:24 AM
Re: Sed /perl/Awk insert - code into user /home/username/.profile
cat /tmp/USERLOCK > /tmp/mycodefile
cat /home/user/.profile >> /tmp/mycodefile
cp/tmp/mycode /home/user/.profile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО03-30-2010 10:15 AM
тАО03-30-2010 10:15 AM
Re: Sed /perl/Awk insert - code into user /home/username/.profile
As always, you guys are tops..