<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Kristijan.org &#187; Shell Scripting</title>
	<atom:link href="http://www.kristijan.org/category/shell-scripting/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kristijan.org</link>
	<description>it's a nerd thing</description>
	<lastBuildDate>Thu, 20 May 2010 00:50:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Calculate total usage in AIX volume group</title>
		<link>http://www.kristijan.org/2010/05/calculate-total-usage-in-aix-volume-group/</link>
		<comments>http://www.kristijan.org/2010/05/calculate-total-usage-in-aix-volume-group/#comments</comments>
		<pubDate>Thu, 20 May 2010 00:50:43 +0000</pubDate>
		<dc:creator>Kristijan</dc:creator>
				<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[aix]]></category>
		<category><![CDATA[ksh]]></category>
		<category><![CDATA[lsvg]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[volume group]]></category>

		<guid isPermaLink="false">http://www.kristijan.org/?p=119</guid>
		<description><![CDATA[When looking at the output of the &#8220;lsvg&#8221; command in AIX, you&#8217;ll see a whole bunch of information regarding the volume group. The PP size, how many PPs are in the volume group, stale PVs, quorum, so on and so on. What I&#8217;m normally looking for when running the &#8220;lsvg&#8221; command is:
1. How much storage [...]]]></description>
			<content:encoded><![CDATA[<p>When looking at the output of the &#8220;lsvg&#8221; command in AIX, you&#8217;ll see a whole bunch of information regarding the volume group. The PP size, how many PPs are in the volume group, stale PVs, quorum, so on and so on. What I&#8217;m normally looking for when running the &#8220;lsvg&#8221; command is:</p>
<p>1. How much storage (PPs) do I have free.<br />
2.How much storage (PPs) is in use.<br />
3.How much storage (PPs) is actually being used.</p>
<p>I can get the first two questions answered looking at the output of &#8220;lsvg&#8221;, but the last one I cannot.<br />
<span id="more-119"></span></p>
<p>Now, lets take a look at the following &#8220;lsvg&#8221; output:</p>
<pre name="code" class="bash:nocontrols">
root@AIX / > lsvg data
VOLUME GROUP:       data                     VG IDENTIFIER:  000771a50000d6000000011bd8f66761
VG STATE:           active                   PP SIZE:        128 megabyte(s)
VG PERMISSION:      read/write               TOTAL PPs:      13410 (1716480 megabytes)
MAX LVs:            256                      FREE PPs:       7729 (989312 megabytes)
LVs:                12                       USED PPs:       5681 (727168 megabytes)
OPEN LVs:           12                       QUORUM:         4
TOTAL PVs:          6                        VG DESCRIPTORS: 6
STALE PVs:          0                        STALE PPs:      0
ACTIVE PVs:         6                        AUTO ON:        yes
MAX PPs per VG:     30480
MAX PPs per PV:     3048                     MAX PVs:        10
LTG size (Dynamic): 256 kilobyte(s)          AUTO SYNC:      no
HOT SPARE:          no                       BB POLICY:      relocatable
</pre>
<p>&#8220;Used PPs&#8221; tells us that 727GB has been allocated to filesystems in the &#8220;data&#8221; volume group. However, the output of a &#8220;df -vg&#8221; shows that only a little over 250GB is actually being used.</p>
<p>This information is helpful to know when you&#8217;re struggling to find space to increase filesystems, or allocate space for a new one. It&#8217;s good to know exactly how much a filesystem is consuming of the potential data allocation in the volume group itself, and how much can be taken for other filesystems to fulfill the allocation request.</p>
<p>Unless there is an AIX command which I haven&#8217;t stumbled across yet, you need to work all this out by doing the following.</p>
<p>1. Do a &#8220;lsvg -l <vgname>&#8221; to find out which filesystems belong to the volume group.<br />
2. Do a &#8220;df -vg&#8221; on each of the filesystems to see how much is actually being used.<br />
3. Add all the values together to get the total sum.</p>
<p>Pain in the ass if you ask me, and the resolution is the exact reason why task automation via shell scripting is great.</p>
<p>Here is a script that I wrote called &#8220;vgusage&#8221;. Put it in /usr/bin and &#8220;chmod +x&#8221; it.</p>
<pre name="code" class="bash:nocontrols">
#!/usr/bin/ksh
#
# Script calculates total usage in a volume group
# and not just space allocated to filesystems.

# Create usage function
usage() {
        echo "USAGE: $0 [k|m|g] [vg]"
}

# Case statement to assign SIZE var
case $1 in
        k)
          SIZE=$1
          SIZEB=KB
          ;;
        m)
          SIZE=$1
          SIZEB=MB
          ;;
        g)
          SIZE=$1
          SIZEB=GB
          ;;
        *)
          usage
          exit 1
          ;;
esac

# Check if $2 exists and assign VG var
if [ -z "$2" ]; then
  usage
  exit 1
else
  VG=$2
fi

# Check that volume group exists
lsvg $VG > /dev/null 2>&#038;1
if [ $? -ne 0 ]; then
  echo "Volume group [$VG] does not exist."
  exit 1
fi

# Create array of all filesystems in volume group
set -A fsname `lsvg -l $VG | awk '{ print $7 }' | awk 'NR!=1' | grep -vE 'LV|N/A'`

# Create array of all filesystem sizes in volume group
count=0
while (( $count < ${#fsname[*]} )); do
           fssize[$count]=`df -v$SIZE "${fsname[$count]}" | awk 'NR!=1' | awk '{ print $3 }'`
        let count="count + 1"
done

# Array loop to print FS and SIZE
count=0
printf "%-30s %s\n" ---------- -------
printf "%-30s %s\n" Filesystem Size-$SIZEB
printf "%-30s %s\n" ---------- -------
while (( $count < ${#fsname[*]} )); do
           printf "%-30s %s\n" ${fsname[$count]} ${fssize[$count]}
        let count="count + 1"
done

# Calculate totals
TOTAL=`echo ${fssize[*]} | awk 'BEGIN {RS=" "} {SUM+=$1} END {print SUM}'`

printf "%-30s %s\n" ----- --------
printf "%-30s %s\n" Total $TOTAL
printf "%-30s %s\n" ----- --------

exit 0
</pre>
<p>The script takes two parameters. The first being the block value (KB, MB, GB), and the second being the name of the volume group.</p>
<pre name="code" class="bash:nocontrols">
root@AIX / > vgusage
USAGE: /usr/bin/vgusage [k|m|g] [vg]
</pre>
<p>Script being run on the data volume group with the output in GB blocks.</p>
<pre name="code" class="bash:nocontrols">
root@AIX / > vgusage g data
----------                     -------
Filesystem                     Size-GB
----------                     -------
/u02                           148.68
/ora/repagg/data01             12.39
/ora/repagg/data02             32.79
/ora/repagg/data03             14.84
/ora/repagg/data04             11.02
/ora/repagg/redo01             0.29
/ora/repagg/redo02             0.29
/app                           0.38
/app/backup                    29.71
/ora/repagg/dat                0.01
/u03                           0.64
-----                          --------
Total                          251.04
-----                          --------
</pre>
<p>As always, post any questions to the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kristijan.org/2010/05/calculate-total-usage-in-aix-volume-group/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Maintain wtmp on AIX</title>
		<link>http://www.kristijan.org/2010/04/maintain-wtmp-on-aix/</link>
		<comments>http://www.kristijan.org/2010/04/maintain-wtmp-on-aix/#comments</comments>
		<pubDate>Tue, 13 Apr 2010 09:44:31 +0000</pubDate>
		<dc:creator>Kristijan</dc:creator>
				<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[aix]]></category>
		<category><![CDATA[bash scripting]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[wtmp]]></category>

		<guid isPermaLink="false">http://www.kristijan.org/?p=116</guid>
		<description><![CDATA[/var/adm/wtmp on AIX maintains a list of past user sessions and information about the restart/shutdown of that particular system. While this file is normally very small in terms of file size, on an active box, this can grow if not properly maintained. You can use the &#8220;last&#8221; command to read wtmp, or export it to [...]]]></description>
			<content:encoded><![CDATA[<p>/var/adm/wtmp on AIX maintains a list of past user sessions and information about the restart/shutdown of that particular system. While this file is normally very small in terms of file size, on an active box, this can grow if not properly maintained. You can use the &#8220;last&#8221; command to read wtmp, or export it to a text file for further processing with &#8220;fwtmp&#8221;. While you can simply redirect nothing into wtmp to empty it out &#8220;>/var/adm/wtmp&#8221;, it&#8217;s always a good idea to keep this file (or at least a backup) for security/auditing reasons.<br />
<span id="more-116"></span></p>
<p>Below is a simple script which will rotate the last 1000 entries in wtmp and discard the rest.</p>
<pre name="code" class="bash:nocontrols">
#!/bin/ksh
#
# Maintain the last 1000 lines in /var/adm/wtmp
# and discard the rest.
#
if [ -s /var/adm/wtmp ]; then
   /usr/sbin/acct/fwtmp < /var/adm/wtmp > /tmp/wtmp.tmp
   /usr/bin/tail -1000 /tmp/wtmp.tmp | /usr/sbin/acct/fwtmp -ic > /var/adm/wtmp
   /usr/bin/rm /tmp/wtmp.tmp
else
   continue
fi
</pre>
<p>Run it out of crontab nightly or whenever suits you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kristijan.org/2010/04/maintain-wtmp-on-aix/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>TSM: Lost Tapes</title>
		<link>http://www.kristijan.org/2009/09/tsm-lost-tapes/</link>
		<comments>http://www.kristijan.org/2009/09/tsm-lost-tapes/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 01:58:16 +0000</pubDate>
		<dc:creator>Kristijan</dc:creator>
				<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[aix]]></category>
		<category><![CDATA[drm]]></category>
		<category><![CDATA[drmedia]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[tsm]]></category>

		<guid isPermaLink="false">http://www.kristijan.org/?p=112</guid>
		<description><![CDATA[We had an issue not long ago were Tivoli Storage Manager was losing track of tapes. The issue ended up being how TSM manages database snapshots which are sent offsite using DRM (Bug in TSM which has been around for a while according to a colleague of mine).
I needed to find out quickly which tapes [...]]]></description>
			<content:encoded><![CDATA[<p>We had an issue not long ago were Tivoli Storage Manager was losing track of tapes. The issue ended up being how TSM manages database snapshots which are sent offsite using DRM (Bug in TSM which has been around for a while according to a colleague of mine).</p>
<p>I needed to find out quickly which tapes TSM had no knowledge of, and had essentially become scratch. I wrote the following script to do just that for me. You&#8217;ll need to tailor it to your environment, as our tapes are bar-coded COL000L4 through to COL120L4.<br />
<span id="more-112"></span></p>
<pre name="code" class="bash:nocontrols">
#!/usr/bin/ksh

dsmadmc="/usr/bin/dsmadmc -id=username -pass=password -dataonly=yes -displ=lis"
count=0
zero=00

echo "The following tapes do not exist in TSM:"
while (( $count <= 120 )); do
        if [ $count -gt 9 ]; then
        let zero=0
        fi

        if [ $count -gt 99 ]; then
        unset zero
        fi

        $dsmadmc q volume ???${zero}${count}?? > /dev/null 2>&#038;1
        if [ $? -ne 0 ]; then
        echo COL${zero}${count}L4
        fi

        let count="count + 1"

done
exit
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.kristijan.org/2009/09/tsm-lost-tapes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Monitor AIX filesystems V2</title>
		<link>http://www.kristijan.org/2009/09/monitor-aix-filesystems-v2/</link>
		<comments>http://www.kristijan.org/2009/09/monitor-aix-filesystems-v2/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 01:34:46 +0000</pubDate>
		<dc:creator>Kristijan</dc:creator>
				<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[aix]]></category>
		<category><![CDATA[filesystem]]></category>
		<category><![CDATA[monitor]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://www.kristijan.org/?p=109</guid>
		<description><![CDATA[I updated this script a while back and made it a lot easier to maintain. It now checks for usage on all mounted filesystems, except for those listed in the $SKIPFS variable.


#!/usr/bin/ksh
#
# This script reports filesystem usages for
# all mounted filesystems.
#
# Filesystems can be excluded by editing the
# SKIPFS variable e.g. SKIPFS='/proc&#124;/test&#124;/home'

MAIL=/usr/bin/mail
RCPT='your@email.com'
USAGE=80
HOSTNAME=`hostname`
SKIPFS='/proc&#124;/test'

set -A fs `df [...]]]></description>
			<content:encoded><![CDATA[<p>I updated this script a while back and made it a lot easier to maintain. It now checks for usage on all mounted filesystems, except for those listed in the $SKIPFS variable.<br />
<span id="more-109"></span></p>
<pre name="code" class="bash:nocontrols">
#!/usr/bin/ksh
#
# This script reports filesystem usages for
# all mounted filesystems.
#
# Filesystems can be excluded by editing the
# SKIPFS variable e.g. SKIPFS='/proc|/test|/home'

MAIL=/usr/bin/mail
RCPT='your@email.com'
USAGE=80
HOSTNAME=`hostname`
SKIPFS='/proc|/test'

set -A fs `df -k | grep -vE $SKIPFS | awk '{ print $4 }' | awk 'NR!=1' | sed 's/%//'`
set -A fn `df -k | grep -vE $SKIPFS | awk '{ print $7 }' | awk 'NR!=1'`

count=0
while (( $count < ${#fs[*]} )); do
        fssize=${fs[$count]}
        if
                [ $fssize -ge $USAGE ]; then
                echo "${fn[$count]} on $HOSTNAME is at ${fssize}%" | $MAIL -s "WARNING on $HOSTNAME" $RCPT
        fi
        let count="count + 1"
done

exit
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.kristijan.org/2009/09/monitor-aix-filesystems-v2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Monitor AIX filesystems</title>
		<link>http://www.kristijan.org/2009/02/monitor-aix-filesystems/</link>
		<comments>http://www.kristijan.org/2009/02/monitor-aix-filesystems/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 03:49:00 +0000</pubDate>
		<dc:creator>Kristijan</dc:creator>
				<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[aix]]></category>
		<category><![CDATA[filesystem]]></category>
		<category><![CDATA[monitor]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.kristijan.org/?p=104</guid>
		<description><![CDATA[If you&#8217;re looking for something cheap and nasty to monitor your filesystem usage while you&#8217;re setting up something more robust, here is a cheap and very nasty script to do just that.


#!/usr/bin/ksh
# This script monitors various filesystems and emails
# notifications when they hit a set limit
#
MAILTO='your@email.com'
HOSTNAME=`hostname`

ROOT=`df -k&#124;grep "/dev/hd4"&#124;awk '{print $4}'&#124;sed "s/%//"`
USR=`df -k&#124;grep "/dev/hd2"&#124;awk '{print $4}'&#124;sed [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re looking for something cheap and nasty to monitor your filesystem usage while you&#8217;re setting up something more robust, here is a cheap and very nasty script to do just that.<br />
<span id="more-104"></span></p>
<pre name="code" class="bash:nocontrols">
#!/usr/bin/ksh
# This script monitors various filesystems and emails
# notifications when they hit a set limit
#
MAILTO='your@email.com'
HOSTNAME=`hostname`

ROOT=`df -k|grep "/dev/hd4"|awk '{print $4}'|sed "s/%//"`
USR=`df -k|grep "/dev/hd2"|awk '{print $4}'|sed "s/%//"`
VAR=`df -k|grep "/dev/hd9var"|awk '{print $4}'|sed "s/%//"`
HOME=`df -k|grep "/dev/hd1"|grep -v opt|awk '{print $4}'|sed "s/%//"`
OPT=`df -k|grep "/opt"|awk '{print $4}'|sed "s/%//"`
TMP=`df -k|grep "/dev/hd3"|awk '{print $4}'|sed "s/%//"`

if [ $ROOT -gt 79 ]
then
   echo "We have hit ${ROOT}% on / on $HOSTNAME"|mailx -s "WARNING on $HOSTNAME" $MAILTO
fi
if [ $USR -gt 79 ]
then
   echo "We have hit ${USR}% on /usr on $HOSTNAME"|mailx -s "WARNING on $HOSTNAME" $MAILTO
fi
if [ $VAR -gt 79 ]
then
   echo "We have hit ${VAR}% on /var on $HOSTNAME"|mailx -s "WARNING on $HOSTNAME" $MAILTO
fi
if [ $HOME -gt 79 ]
then
   echo "We have hit ${HOME}% on /home on $HOSTNAME"|mailx -s "WARNING on $HOSTNAME" $MAILTO
fi
if [ $OPT -gt 79 ]
then
   echo "We have hit ${OPT}% on /opt on $HOSTNAME"|mailx -s "WARNING on $HOSTNAME" $MAILTO
fi
if [ $TMP -gt 79 ]
then
   echo "We have hit ${TMP}% on /tmp on $HOSTNAME"|mailx -s "WARNING on $HOSTNAME" $MAILTO
fi

exit
</pre>
<p>The above script is running on an AIX operating environment, so you&#8217;ll need to modify the variables to suit. It&#8217;s not all that far to figure out, but if you need a hand&#8230;shout out.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kristijan.org/2009/02/monitor-aix-filesystems/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Split and Reassemble files</title>
		<link>http://www.kristijan.org/2008/12/split-and-reassemble-files/</link>
		<comments>http://www.kristijan.org/2008/12/split-and-reassemble-files/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 00:20:39 +0000</pubDate>
		<dc:creator>Kristijan</dc:creator>
				<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[bash scripting]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[reassemble]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[split]]></category>

		<guid isPermaLink="false">http://www.kristijan.org/?p=86</guid>
		<description><![CDATA[I wrote this a few years back for LinuxQuestions.org. It was around 2004 from memory, and majority of the mail servers in Internet land only allowed for 2MB file attachments. This has now change, but I thought I&#8217;d post the article anyway.
There always comes a time, where you wish that file was only a few [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote this a few years back for LinuxQuestions.org. It was around 2004 from memory, and majority of the mail servers in Internet land only allowed for 2MB file attachments. This has now change, but I thought I&#8217;d post the article anyway.</p>
<p>There always comes a time, where you wish that file was only a few kilobytes/megabytes smaller. Whether it be so it can fit onto your floppy disk, CD-R etc, or so you can meet the attachment limit on an e-mail server. This isn&#8217;t really a command that you would use everyday, but it might come in handy.</p>
<p><strong><u>Splitting the file</u></strong></p>
<pre name="code" class="html:nocontrols:nogutter">
kristijan@slackware testing$ ls -lh
total 13M
-rw-rw-r--  1 kristijan users 13M Jul 23 18:18 karaoke.mp3
</pre>
<p>Just say we wanted to e-mail this file to a friend, but the e-mail server only allowed a maximum of 2MB attachments.</p>
<p>(Note** I like to play safe, so I will make my chunks of data 1.9M)</p>
<p>1.9 x 1024 = 1945.6</p>
<p>(Note** To play safe once again, I will leave out the decimal and just use 1945)</p>
<p>The command that we will use is:
<pre name="code" class="html:nocontrols:nogutter">
kristijan@slackware testing$ split -b 1945k karaoke.mp3</pre>
<pre name="code" class="html:nocontrols:nogutter">
kristijan@slackware testing$ split -b 1945k karaoke.mp3
kristijan@slackware testing$ ls -lh
total 26M
-rw-rw-r--  1 kristijan users  13M Jul 23 18:18 karaoke.mp3
-rw-rw-r--  1 kristijan users 1.9M Jul 23 18:22 xaa
-rw-rw-r--  1 kristijan users 1.9M Jul 23 18:22 xab
-rw-rw-r--  1 kristijan users 1.9M Jul 23 18:22 xac
-rw-rw-r--  1 kristijan users 1.9M Jul 23 18:22 xad
-rw-rw-r--  1 kristijan users 1.9M Jul 23 18:22 xae
-rw-rw-r--  1 kristijan users 1.9M Jul 23 18:22 xaf
-rw-rw-r--  1 kristijan users 1.4M Jul 23 18:22 xag
</pre>
<p>OK, what we have now done is told &#8217;split&#8217; to use bytes per output file (-b). For more information and arguments on split, view the man pages (man split). Split how now &#8217;split&#8217; karaoke.mp3 into 7 smaller files named &#8216;xaa&#8217;, &#8216;xab&#8217;, &#8216;xac&#8217; etc, which are all under 2M in size.</p>
<p>These files now meet the e-mail server&#8217;s attachment limit and can be sent.</p>
<p><strong><u>Recreating the file (cat)</u></strong></p>
<p>Recreation of the karaoke.mp3 is even easier. For this, we will be using &#8216;cat&#8217;. See the man pages for more information on &#8216;cat&#8217; (man cat).</p>
<p>The command that we will use is:</p>
<pre name="code" class="html:nocontrols:nogutter">kristijan@slackware testing$ cat xa* > karaoke-restored.mp3
</pre>
<p>(Note** Before removing the original file, I recommend that you make a backup of it)</p>
<pre name="code" class="html:nocontrols:nogutter">
kristijan@slackware testing$ rm karaoke.mp3
kristijan@slackware testing$ ls -lh
-rw-rw-r--  1 kristijan users 1.9M Jul 23 18:22 xaa
-rw-rw-r--  1 kristijan users 1.9M Jul 23 18:22 xab
-rw-rw-r--  1 kristijan users 1.9M Jul 23 18:22 xac
-rw-rw-r--  1 kristijan users 1.9M Jul 23 18:22 xad
-rw-rw-r--  1 kristijan users 1.9M Jul 23 18:22 xae
-rw-rw-r--  1 kristijan users 1.9M Jul 23 18:22 xaf
-rw-rw-r--  1 kristijan users 1.4M Jul 23 18:22 xag
kristijan@slackware testing$ cat xa* > karaoke-restored.mp3
kristijan@slackware testing$ ls -lh
total 26M
-rw-rw-r--  1 kristijan users  13M Jul 23 18:39 karaoke-restored.mp3
-rw-rw-r--  1 kristijan users 1.9M Jul 23 18:22 xaa
-rw-rw-r--  1 kristijan users 1.9M Jul 23 18:22 xab
-rw-rw-r--  1 kristijan users 1.9M Jul 23 18:22 xac
-rw-rw-r--  1 kristijan users 1.9M Jul 23 18:22 xad
-rw-rw-r--  1 kristijan users 1.9M Jul 23 18:22 xae
-rw-rw-r--  1 kristijan users 1.9M Jul 23 18:22 xaf
-rw-rw-r--  1 kristijan users 1.4M Jul 23 18:22 xag
</pre>
<p>By using cat, we have now recreated the original file. The &#8216;xaa&#8217;, xab&#8217; etc files may now be deleted.</p>
<p>There we have it, the karaoke file is now restored and can be played as per normal.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kristijan.org/2008/12/split-and-reassemble-files/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Sending files to multiple Windows hosts</title>
		<link>http://www.kristijan.org/2008/12/sending-files-to-multiple-windows-hosts/</link>
		<comments>http://www.kristijan.org/2008/12/sending-files-to-multiple-windows-hosts/#comments</comments>
		<pubDate>Sun, 21 Dec 2008 10:22:07 +0000</pubDate>
		<dc:creator>Kristijan</dc:creator>
				<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[bash scripting]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[windows]]></category>
		<category><![CDATA[windows xp]]></category>

		<guid isPermaLink="false">http://www.kristijan.org/?p=71</guid>
		<description><![CDATA[A few months ago at work, I needed to send a number of files to a little over 100 Windows workstations. I had administrator rights on all these workstations, and luckily for me, they all had the same administrator password.
I had access to a Red Hat AS4 server, so I wrote a shell script to [...]]]></description>
			<content:encoded><![CDATA[<p>A few months ago at work, I needed to send a number of files to a little over 100 Windows workstations. I had administrator rights on all these workstations, and luckily for me, they all had the same administrator password.</p>
<p>I had access to a Red Hat AS4 server, so I wrote a shell script to read all the hostnames of the workstations from a text file, mount each C$ share via CIFS, copy the necessary files, unmount and repeat.</p>
<p>Over the past few weeks, I added a few other things which I were of use (ping check prior to send, file verification on remote workstation).</p>
<pre name="code" class="bash:nocontrols">
#!/bin/bash
#
# Script to send files to Windows workstations

# set -x

function runPingCheck ()
{
	grep -vE '^$|^#' callcentres/$name.txt | while read i
        do ping -c 1 `echo $i | awk '{print $1}'`.fqdn.com &#038;> /dev/null
                if [ $? -gt 0 ]; then
                        echo -e "$i ... PING FAIL"
                fi

        done
	echo ""
	echo "Check complete"
	echo ""
	echo -n "Continue with send(Y/N) [Y]? "
	read contsend
		case "$contsend" in
			N|n) exit 1 ;;
			Y|y|*) runSendFiles ;;
		esac
}

function runSendFiles ()
{
	echo "Send started `date`" | tee -a $name.log

	grep -vE '^$|^#' callcentres/$name.txt | while read i
        do ping -c 1 `echo $i | awk '{print $1}'`.fqdn.com &#038;> /dev/null
                if [ $? -gt 0 ]; then
                        echo "$i ... Host Offline" | tee -a $name.log
                        continue
                fi

                mount -t cifs //`echo $i | awk '{print $1}'`.fqdn.com/c$ /mnt/winmnt -o user=administrator,pass=PASSHERE
                if [ $? -gt 0 ]; then
                        echo "$i ... Failed CIFS Mount" | tee -a $name.log
                else
                        cp -R ./files/* /mnt/winmnt
                                if [ -e /mnt/winmnt/sent.tmp ]; then
                                        rm /mnt/winmnt/sent.tmp
                                        umount /mnt/winmnt
                                        echo "$i ... Complete" | tee -a $name.log
                                else
                                        umount /mnt/winmnt
                                        echo "$i ... Failed File Verification" | tee -a $name.log
                                fi
                fi
        done

	echo "Send completed `date`" | tee -a $name.log
}

ls ./callcentres | sed 's/.txt//g'
echo ""
echo -n "Type the name of the call centre you wish to upgrade: "
read name

echo ""
echo -n "Would you like to run a ping check before you send(Y/N) [Y]? "
read pingcheck

case "$pingcheck" in
	N|n) runSendFiles ;;
	Y|y|*) runPingCheck ;;
esac

exit 0
</pre>
<p>The basic directory structure looks like this:<br />
/callcentres<br />
     &#8211; melbourne.txt<br />
/files<br />
/sendscript.sh</p>
<p>melbourne.txt just had a list of all the hostnames, each on its own line. (# can be used at the start of any line to skip a particular workstation).</p>
<pre name="code" class="bash:nocontrols">
host1
#host2
host3
...
host100
</pre>
<p>/files contains any file that you want to send to the remote Windows host. Take note that you need to provide the absolute path of the Windows location (e.g. /files/Program Files/)</p>
<p>Output of the script will be logged to STDOUT and to a log file in the root directory where sendscript.sh resides.</p>
<p>Once you have the file structure and sendscript.sh in order, simply run the script. You will be prompted for the name of the &#8220;call centre&#8221; you wish to send files to. In this example, you would enter <strong>melbourne</strong>. Then you will be asked if you&#8217;d like to run a ping check on each workstation prior to the file send.</p>
<p>Happy sending <img src='http://www.kristijan.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.kristijan.org/2008/12/sending-files-to-multiple-windows-hosts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Unrar TV show packs</title>
		<link>http://www.kristijan.org/2008/12/unrar-tv-show-packs/</link>
		<comments>http://www.kristijan.org/2008/12/unrar-tv-show-packs/#comments</comments>
		<pubDate>Sun, 21 Dec 2008 09:49:15 +0000</pubDate>
		<dc:creator>Kristijan</dc:creator>
				<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[bash scripting]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[the big bang theory]]></category>

		<guid isPermaLink="false">http://www.kristijan.org/?p=62</guid>
		<description><![CDATA[We all download TV shows, there is no use denying it. I recently got pointed in the directory of a rather funny show called The Big Bang Theory. I grabbed the first episode of season 1, saw what I liked, then grabbed the entire season 1 pack.
17 episodes, each in their own folder in .rar [...]]]></description>
			<content:encoded><![CDATA[<p>We all download TV shows, there is no use denying it. I recently got pointed in the directory of a rather funny show called The Big Bang Theory. I grabbed the first episode of season 1, saw what I liked, then grabbed the entire season 1 pack.</p>
<p>17 episodes, each in their own folder in .rar files.<br />
What a pain in the ass!</p>
<p>Instead of clicking away at each RAR file individually, I put together a little bash script to do the work for me which I&#8217;ve called <strong>unrar_all</strong>.</p>
<pre name="code" class="bash:nocontrols">
#!/bin/bash
#
# Script to unrar season packs of TV shows
# Put it in the directory containing all the directorys
#
# eg.
#       Big_Bang_Theory.1x01.Pilot.DVDRip_XviD-FoV/
#       Big_Bang_Theory.1x02.The_Big_Bran_Hypothesis.DVDRip_XviD-FoV/
#       Big_Bang_Theory.1x03.The_Fuzzy_Boots_Corollary.DVDRip_XviD-FoV/
#       unrar_all

find . -type d -print | while read i
        do pushd .
        cd $i
                unset partrar
                partrar=`find . -name *part01.rar`
                if [ -n "$partrar" ]; then
                unrar e *part01.rar
                mv *.avi ../
                popd
        else
                unrar e *.rar
                mv *.avi ../
                popd
        fi
done
</pre>
<p>This script requires <a href="http://www.rarlab.com/rar_add.htm">unrar</a> from RARLabs.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kristijan.org/2008/12/unrar-tv-show-packs/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
