- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Quick scripting query
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
Forums
Discussions
Discussions
Discussions
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
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
12-12-2002 03:53 AM
12-12-2002 03:53 AM
I'm in the process of modifying a series of files in one particular directory.
I have attached a copy of the file I need to modify.
Our domain name has changed therefore need to change this in the files. I need to change the line towards the bottom which has the name of the host with it's fully qualified domain name.
This line currently reads:
HOST "dwnps006-mgt.domainx.com" dwnps006-mgt.domainx.com
I need to change this to:
HOST "dwnps006.it.newdomain.net" dwnps006.it.newdomain.net
I need to do this for about 35-40 files. Obviously each host name is different. The name of the host is also in the first line of the file: (after Quotes and before underscore)
DATALIST "dwnps006_system_adhoc"
So first I will need to put hostname in a variable then use this and replace everything after HOST with:
HOST "$hostname.it.newdomain.net" $hostname.it.newdomain.net
I hope this is a straight forward problem. How would I put hostname into a variable so that I can use it to replace old FQDN with new one.
Thanks, any help much appreciated.
Regards,
Mohammed.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2002 04:02 AM
12-12-2002 04:02 AM
Re: Quick scripting query
hostname=yourhost
HOST "`$hostname`.it.newdomain.net" $hostname.it.newdomain.net
regards,
U.SivaKumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2002 04:04 AM
12-12-2002 04:04 AM
Re: Quick scripting query
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2002 04:06 AM
12-12-2002 04:06 AM
Re: Quick scripting query
If domain part is constant.
hostname=yourhostname.it.newdomain.net
HOST "$hostname" $hostname
regards,
U.SivaKumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2002 04:15 AM
12-12-2002 04:15 AM
Re: Quick scripting query
Here's a little script.
awk ' {
FS = "-"
printf "%s.it.newdomain.net\n", $1 } ' fileName.in
Tom
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2002 04:28 AM
12-12-2002 04:28 AM
Re: Quick scripting query
Here's a script:
#!/usr/bin/ksh
#
# PUT your 35-40 file names in /tmp/filelist
# BUT make sure you use the FULL PATH NAME
#
for fname in `cat /tmp/filelist`
do
cat $fname|eval `head -1 $fname|cut -d'"' -f2|cut -d'_' -f1|sed "s/.*/sed \"s_&-
mgt.domainx.com_&.it.newdomain.net_g\"/"`>${fname}TEMP
mv ${fname}TEMP $fname
done
So /tmp/filelist would look like this:
/somepath/somefile1
/somepath/somefile2
...
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2002 04:36 AM
12-12-2002 04:36 AM
Re: Quick scripting query
For i in file1 file2 file3 ...
do
cp $i $i.origcopy
sed "s/dwnps006-mgt.domainx.com/dwnps006.it.newdomain.net/g" $i > $i.tmpcopy
cp $i.tmpcopy $i
done
Once you have done this you can check the files, if everything is messed up replace the .orig files. Once you are sure everything is fine remove the .tmpcopy and .origcopy files.
Kind regards,
Robert Thorneycroft
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2002 04:39 AM
12-12-2002 04:39 AM
Re: Quick scripting query
In the above message sed and the next two lines are all part of the same line.
Damn editor needs longer line lengths :(
Regards.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2002 04:54 AM
12-12-2002 04:54 AM
Re: Quick scripting query
an easy way to do so would be:
1. create a file /tmp/filelist containing the list of files you want to update
2. create then run this script:
#! /usr/bin/ksh
for i in `cat /tmp/filelist`
do
sed 's/dwnps006-mgt.domainx.com/dwnps006.it.newdomain/g' $i > /tmp/tempfile
mv tmpfile $i
done
tested on your file
Hope this helps
FiX
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2002 07:26 AM
12-12-2002 07:26 AM
Re: Quick scripting query
The hostname dwnps006 is just in that one file. Every other file has a different hostname. This host name is at the top of the file after DATALIST " and before the _
So Ideally I would want to cut the hostname put it in a variable and use that variable at the bottom of the file appending the new FQDN.
By the way... I have to do this for 137 files in dir not 35-40 :)
Regards,
Mohammed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2002 08:00 AM
12-12-2002 08:00 AM
Re: Quick scripting query
Thanks.
Regards,
Mohammed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2002 08:11 AM
12-12-2002 08:11 AM
Re: Quick scripting query
I may miss something here, but this seems to a very simple task
like
perl -i.bak -npe 's/domainx\.com/newdoain\.net/g' filelist
where filelist are the 1000 files you need to change.
Perl's in-place option saves us a backup copy of with the extension .bak in my example of each file, and writes changes to your original files.
If you don't want to specify your filelist use shell globbing or command subtitution from an ls or supply a file with the list
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2002 08:42 AM
12-12-2002 08:42 AM
SolutionI didn't realise the hostname var a parameter...
Will this be what you wanted?
same process as before, put all file names in /tmp/filelist
The shell script becomes:
#! /usr/bin/ksh
for i in `cat /tmp/filelist`
do
host_name=`grep DATALIST test|sed 's/.*DATALIST \"//'|sed 's/_.*//'`
sed 's/"${host_name}"-mgt.domainx.com/"${host_name}".it.newdomain/g' $i > /tmp/tmpfile
mv tmpfile $i
done
Would this be what you're looking for? I know the host_name calculation is not very pretty, but it works ;-)
Cheers,
FiX
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2002 12:40 AM
12-13-2002 12:40 AM
Re: Quick scripting query
Something like this
# cd /tothedirwherefilesexists
# find . -type f -print > /tmp/1
# for fil in $(cat /tmp/1)
> do
> sed 's/\([a-z][a-z]*\)-mgt.domainx.com/\1.it.newdomain.net' > ${fil}.new
>done
#
now after testing ${fil}.new files rename them
Sundar.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2002 06:53 AM
12-13-2002 06:53 AM