Linux scripting

Computers, gadgets, electronics, mobiles, networking - it's all here.
Post Reply
User avatar
Jetboy
Posts: 1283
Joined: Tue Jan 18, 2005 5:52 pm
Location: Palmerston North
Contact:

Linux scripting

Post by Jetboy » Fri Aug 22, 2008 9:59 pm

Right....if your not into Linux in a big way then you should probably go back to watching youtube videos about now

Have a small issue here at work at the moment, have a fleet of workstations that I've just rolled out, they are windows with a Fedora 7 Virtual Machine running on it.
The VM has a simulation software package on it that requires a few files to be specific to each installation and while we have a contractor coming over in a week or two thats a Linux guru I need to get this squared away by monday (last resort is manually editing 50+ VM's)

What I want to do is run a script that edits the various folders and files on each VM to be based on their hostname

Need a folder on the install "/m88" changed to the VM hostname ie "/jsaf88" (or a copy made with the new name..just realised that is an option as well)
Then need files within that folder containing "m88" to have that replaced with the hostname...some are file names and also text within files (only 1 file need txt within the file changed otherwise the files can be copied and renamed with the old ones left as they are)

Have a few scripts allready from the contractor (perth based so managed to catch him on skype before he went home for the day), not yet tried these but is what I'm starting with

Sets hostname based on IP address
#!/bin/bash
# get last octet of lan ip address
IP=`/sbin/ifconfig | grep "inet addr" | grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1 }' | cut -d. -f4 | awk '{ print $1 }'`
hostname pc-$IP

semi-automated backups
#!/bin/bash
# get hostname
HOSTNAME=`hostname`
# get time stamp
DATE=`date -dtoday '+%d-%m-%Y-%X' | awk '{ print $1 }'`
# tar up current overlays and move to JSAF share directory
tar -cvzf /mnt/JSAF_Shares/overlays/overlays.$HOSTNAME.$DATE.tar.gz /usr/stow/JSAF5/overlays

All the above are run via a script that executes them based on a pre-built IP list

User avatar
johnny2combs
Posts: 161
Joined: Thu Apr 12, 2007 9:56 am

Re: Linux scripting

Post by johnny2combs » Sat Aug 23, 2008 12:34 am

Jetboy wrote:Right....if your not into Linux in a big way then you should probably go back to watching youtube videos about now

Have a small issue here at work at the moment, have a fleet of workstations that I've just rolled out, they are windows with a Fedora 7 Virtual Machine running on it.
The VM has a simulation software package on it that requires a few files to be specific to each installation and while we have a contractor coming over in a week or two thats a Linux guru I need to get this squared away by monday (last resort is manually editing 50+ VM's)

What I want to do is run a script that edits the various folders and files on each VM to be based on their hostname

Need a folder on the install "/m88" changed to the VM hostname ie "/jsaf88" (or a copy made with the new name..just realised that is an option as well)
Then need files within that folder containing "m88" to have that replaced with the hostname...some are file names and also text within files (only 1 file need txt within the file changed otherwise the files can be copied and renamed with the old ones left as they are)

Have a few scripts allready from the contractor (perth based so managed to catch him on skype before he went home for the day), not yet tried these but is what I'm starting with

Sets hostname based on IP address
#!/bin/bash
# get last octet of lan ip address
IP=`/sbin/ifconfig | grep "inet addr" | grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1 }' | cut -d. -f4 | awk '{ print $1 }'`
hostname pc-$IP

semi-automated backups
#!/bin/bash
# get hostname
$HOSTNAME=`hostname` OR HOSTNAME=`$hostname`
# get time stamp
$DATE=`date -dtoday '+%d-%m-%Y-%X' | awk '{ print $1 }'` OR DATE=`$date -dtoday '+%d-%m-%Y-%X' | awk '{ print $1 }'`
# tar up current overlays and move to JSAF share directory
tar -cvzf /mnt/JSAF_Shares/overlays/overlays.$HOSTNAME.$DATE.tar.gz /usr/stow/JSAF5/overlays

All the above are run via a script that executes them based on a pre-built IP list
I think that's whats missing Jetboy, may be wrong. Only because you have on the last line

tar -cvzf /mnt/JSAF_Shares/overlays/overlays.$HOSTNAME.$DATE.tar.gz /usr/stow/JSAF5/overlays
No matter how loudly you shout @ the monitor, The other players won't hear you.

Post Reply