<?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>Ramblings of a sysadmin</description>
	<lastBuildDate>Wed, 26 Oct 2011 10:19:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Quickly show memory usage under AIX</title>
		<link>http://www.kristijan.org/2011/01/quickly-show-memory-usage-under-aix/</link>
		<comments>http://www.kristijan.org/2011/01/quickly-show-memory-usage-under-aix/#comments</comments>
		<pubDate>Wed, 05 Jan 2011 23:36:40 +0000</pubDate>
		<dc:creator>Kristijan</dc:creator>
				<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[aix]]></category>
		<category><![CDATA[ksh]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[usage]]></category>

		<guid isPermaLink="false">http://www.kristijan.org/?p=183</guid>
		<description><![CDATA[Very quick and basic shell script to show total/free/used memory on a host running AIX.

kristijan@AIX &#62; ./meminfo
&#160;
Memory Information
==================
total memory = 1884 MB
free memory  = 94 MB
used memory  = 1790 MB


Script uses standard AIX command line utilities to work out all the values.  [...]]]></description>
			<content:encoded><![CDATA[<p>Very quick and basic shell script to show total/free/used memory on a host running AIX.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">kristijan@AIX &gt; ./meminfo
&nbsp;
Memory Information
==================
total memory = 1884 MB
free memory  = 94 MB
used memory  = 1790 MB</pre></div></div>

<p><span id="more-183"></span></p>
<p>Script uses standard AIX command line utilities to work out all the values. I haven&#8217;t tested it across all versions of AIX (I wrote this on AIX 6.1), but I believe it should work fine. Let me know in the comments if it doesn&#8217;t.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/ksh</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Quick view of memory usage under AIX</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
<span style="color: #007800;">USED</span>=<span style="color: #000000; font-weight: bold;">`</span>svmon <span style="color: #660033;">-G</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #660033;">-2</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ print $3 }'</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">USED</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #007800;">$USED</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000;">256</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">TOTAL</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">lsattr</span> <span style="color: #660033;">-El</span> sys0 <span style="color: #660033;">-a</span> realmem <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ print $2 }'</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">TOTAL</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #007800;">$TOTAL</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000;">1000</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">FREE</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #007800;">$TOTAL</span> - <span style="color: #007800;">$USED</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>Memory Information&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;==================&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;total memory = <span style="color: #007800;">$TOTAL</span> MB&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;free memory  = <span style="color: #007800;">$FREE</span> MB&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;used memory  = <span style="color: #007800;">$USED</span> MB&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></div></div>

<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://www.kristijan.org/2011/01/quickly-show-memory-usage-under-aix/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Automount AFP shares in OSX</title>
		<link>http://www.kristijan.org/2010/11/automount-afp-shares-in-osx/</link>
		<comments>http://www.kristijan.org/2010/11/automount-afp-shares-in-osx/#comments</comments>
		<pubDate>Fri, 12 Nov 2010 11:03:10 +0000</pubDate>
		<dc:creator>Kristijan</dc:creator>
				<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[afp]]></category>
		<category><![CDATA[autofs]]></category>
		<category><![CDATA[automount]]></category>
		<category><![CDATA[mount]]></category>
		<category><![CDATA[osx]]></category>

		<guid isPermaLink="false">http://www.kristijan.org/?p=137</guid>
		<description><![CDATA[So I&#8217;ve finally got around to building my NAS. It&#8217;s a pretty 12TB FreeNAS using RAIDZ&#8230;she runs very nicely   At first, I was using SMB, but found the performance from AFP better, that&#8217;s for another post though. For the life of me, I couldn&#8217;t find the &#8220;Mac&#8221; way of auto mounting an AFP share. So  [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve finally got around to building my NAS. It&#8217;s a pretty 12TB FreeNAS using RAIDZ&#8230;she runs very nicely <img src='http://www.kristijan.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  At first, I was using SMB, but found the performance from AFP better, that&#8217;s for another post though. For the life of me, I couldn&#8217;t find the &#8220;Mac&#8221; way of auto mounting an AFP share. So being the sysadmin ninja that I am, I just went along and did it my own way.</p>
<p>Luckily for us, the pretty OSX frontend sits on top of a UNIX backend. In short, I ended up using autofs, and it works rather well. Below is how to get it working.<br />
<span id="more-137"></span><br />
1. Bust open Terminal.app and do the following.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">sudo vi /etc/fstab</pre></div></div>

<p>&#8230;and paste the below:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;"># Mount AFP share from NAS
(hostname):(share) (mount_point) url automounted,url==afp://(username):(password)@(hostname)/(share) (mount_point) 0 0</pre></div></div>

<p>Replacing the following:<br />
(hostname):(share) &#8211; With the hostname and share of the NAS.<br />
(mount_point) &#8211; The mount point in OSX.<br />
(username):(password) &#8211; Credentials to connect to the share.</p>
<p>For example:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">192.168.0.109:/Media /Users/kristijan/Media url automounted,url==afp://kristijan:fakepass@192.168.0.109/Media /Users/kristijan/Media 0 0</pre></div></div>

<p>2. Either reboot or run &#8220;sudo automount -vc&#8221; to mount your share.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">iMac:~ kristijan$ sudo automount -vc
automount: /net updated
automount: /home updated
automount: /Users/kristijan/Media mounted
automount: no unmounts</pre></div></div>

<p>All done.<br />
Since we&#8217;re using autofs, NAS&#8217;s that hibernate shouldn&#8217;t cause OSX any issues, as autofs can mount/umount as needed.</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://www.kristijan.org/2010/11/automount-afp-shares-in-osx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Keeping an eye on TSM volumes</title>
		<link>http://www.kristijan.org/2010/09/keeping-an-eye-on-tsm-volumes/</link>
		<comments>http://www.kristijan.org/2010/09/keeping-an-eye-on-tsm-volumes/#comments</comments>
		<pubDate>Tue, 21 Sep 2010 03:29:21 +0000</pubDate>
		<dc:creator>Kristijan</dc:creator>
				<category><![CDATA[Shell Scripting]]></category>
		<category><![CDATA[monitor]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[tsm]]></category>

		<guid isPermaLink="false">http://www.kristijan.org/?p=126</guid>
		<description><![CDATA[I wrote a quick script which tells me when volumes in TSM (Tivoli Storage Manager) have access and/or media issues and shoots me off an email. The script does two things:
1) Checks for volumes which are NOT in the states READWRITE or OFFSITE.
2) Checks for volumes which have a read/write error  [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote a quick script which tells me when volumes in TSM (Tivoli Storage Manager) have access and/or media issues and shoots me off an email. The script does two things:</p>
<p>1) Checks for volumes which are NOT in the states READWRITE or OFFSITE.<br />
2) Checks for volumes which have a read/write error count >0.</p>
<p>I&#8217;m sure that most people running TSM in their environment have some sort of daily reporting that gets sent out. If that&#8217;s the case, you can simply extract the SQL from the script and use it in your own reporting tools.<br />
<span id="more-126"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/ksh</span>
&nbsp;
<span style="color: #007800;">USER</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> USER <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>aixuser<span style="color: #000000; font-weight: bold;">/</span>tsm_creds <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> = <span style="color: #ff0000;">'{ print $2 }'</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">PASS</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> PASS <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>aixuser<span style="color: #000000; font-weight: bold;">/</span>tsm_creds <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> = <span style="color: #ff0000;">'{ print $2 }'</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #007800;">DSMADMC</span>=<span style="color: #ff0000;">&quot;/usr/bin/dsmadmc -id=<span style="color: #007800;">$USER</span> -pass=<span style="color: #007800;">$PASS</span> -dataonly=yes&quot;</span>
<span style="color: #007800;">DATE</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #ff0000;">&quot;%Y%m%d&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">DATE_SHORT</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #ff0000;">&quot;%a&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">TEMP_OLD</span>=<span style="color: #ff0000;">&quot;/tmp/tsm.temp.old&quot;</span>
<span style="color: #007800;">TEMP_NEW</span>=<span style="color: #ff0000;">&quot;/tmp/tsm.temp.new&quot;</span>
<span style="color: #007800;">MAILTO</span>=<span style="color: #ff0000;">&quot;email@host.com&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$TEMP_OLD</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #007800;">$TEMP_OLD</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #007800;">MACRO1</span>=<span style="color: #ff0000;">&quot;select VOLUME_NAME,ACCESS from volumes where access !='READWRITE' and access !='OFFSITE'&quot;</span>
&nbsp;
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;VOLUMES WITH STATUS ISSUES&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$TEMP_NEW</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>VOLUME_NAME            ACCESS&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$TEMP_NEW</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;------------------     ------------------&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$TEMP_NEW</span>
    <span style="color: #007800;">$DSMADMC</span> <span style="color: #007800;">$MACRO1</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$TEMP_NEW</span>
&nbsp;
<span style="color: #007800;">MACRO2</span>=<span style="color: #ff0000;">&quot;SELECT volumes.volume_name, volumes.stgpool_name, volumes.pct_utilized, volumes.status, volumes.write_errors, volumes.read_errors FROM volumes, libvolumes WHERE volumes.volume_name=libvolumes.volume_name AND ( volumes.write_errors&gt;0 OR volumes.read_errors&gt;0 )&quot;</span>
&nbsp;
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>VOLUMES WITH READ/WRITE ISSUES&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$TEMP_NEW</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>VOLUME_NAME            STGPOOL_NAME           PCT_UTILIZED     STATUS                 WRITE_ERRORS     READ_ERRORS&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$TEMP_NEW</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;------------------     ------------------     ------------     ------------------     ------------     -----------&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$TEMP_NEW</span>
    <span style="color: #007800;">$DSMADMC</span> <span style="color: #007800;">$MACRO2</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$TEMP_NEW</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">diff</span> <span style="color: #007800;">$TEMP_OLD</span> <span style="color: #007800;">$TEMP_NEW</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span>
   <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> == <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$TEMP_NEW</span> <span style="color: #000000; font-weight: bold;">|</span> mail <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;Warning: TSM Media Issues&quot;</span> <span style="color: #007800;">$MAILTO</span>
    <span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #007800;">$TEMP_NEW</span> <span style="color: #007800;">$TEMP_OLD</span>
   <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #007800;">$TEMP_NEW</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exit</span></pre></td></tr></table></div>


<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">aixuser@TSM /home/aixuser &gt; cat tsm_creds
USER=tsmuser
PASS=tsmpass
aixuser@TSM /home/aixuser &gt; ls -l
-r--------   1 aixuser     system           27 May 17 14:42 tsm_creds
-rwxr-xr-x   1 aixuser     system         1605 Sep 21 10:55 tsm_tape_issues</pre></div></div>

<p>Script breakdown<br />
Line(s)<br />
<b>03-04:</b>&nbsp;&nbsp;&nbsp;I grab the TSM credentials out of a file which only has o+r access rights so we don&#8217;t have the TSM credentials in the script itself (see above output).<br />
<b>17:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SQL select statement to search for all volumes with access other than READWRITE and OFFSITE.<br />
<b>24:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SQL select statement to search for all volumes with read/write errors.<br />
<b>31-35:</b>&nbsp;&nbsp;&nbsp;diff new output with previously saved output and determine if email should be sent.</p>
<p>It&#8217;s pretty straight forward, nothing fancy. Just change the variables to cater for your environment and off you go. The result will be an email with output similiar to the below if any issues are found.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">VOLUMES WITH STATUS ISSUES
&nbsp;
VOLUME_NAME            ACCESS
------------------     ------------------
TAPE09L4               UNAVAILABLE       
&nbsp;
&nbsp;
VOLUMES WITH READ/WRITE ISSUES
&nbsp;
VOLUME_NAME            STGPOOL_NAME           PCT_UTILIZED     STATUS                 WRITE_ERRORS     READ_ERRORS
------------------     ------------------     ------------     ------------------     ------------     -----------
TAPE09L4               PRI_TAPE_POOL                  13.7     FULL                              0               1</pre></div></div>

<p>Post any questions to the comments box below.</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://www.kristijan.org/2010/09/keeping-an-eye-on-tsm-volumes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<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>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">root@AIX / &gt; 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></div></div>

<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>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/ksh</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Script calculates total usage in a volume group</span>
<span style="color: #666666; font-style: italic;"># and not just space allocated to filesystems.</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Create usage function</span>
usage<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;USAGE: $0 [k|m|g] [vg]&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Case statement to assign SIZE var</span>
<span style="color: #000000; font-weight: bold;">case</span> $<span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">in</span>
        k<span style="color: #7a0874; font-weight: bold;">&#41;</span>
          <span style="color: #007800;">SIZE</span>=$<span style="color: #000000;">1</span>
          <span style="color: #007800;">SIZEB</span>=KB
          <span style="color: #000000; font-weight: bold;">;;</span>
        m<span style="color: #7a0874; font-weight: bold;">&#41;</span>
          <span style="color: #007800;">SIZE</span>=$<span style="color: #000000;">1</span>
          <span style="color: #007800;">SIZEB</span>=MB
          <span style="color: #000000; font-weight: bold;">;;</span>
        g<span style="color: #7a0874; font-weight: bold;">&#41;</span>
          <span style="color: #007800;">SIZE</span>=$<span style="color: #000000;">1</span>
          <span style="color: #007800;">SIZEB</span>=GB
          <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
          usage
          <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
          <span style="color: #000000; font-weight: bold;">;;</span>
<span style="color: #000000; font-weight: bold;">esac</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Check if $2 exists and assign VG var</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;$2&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
  usage
  <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">else</span>
  <span style="color: #007800;">VG</span>=$<span style="color: #000000;">2</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;"># Check that volume group exists</span>
lsvg <span style="color: #007800;">$VG</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Volume group [<span style="color: #007800;">$VG</span>] does not exist.&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Create array of all filesystems in volume group</span>
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #660033;">-A</span> fsname <span style="color: #000000; font-weight: bold;">`</span>lsvg <span style="color: #660033;">-l</span> <span style="color: #007800;">$VG</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ print $7 }'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'NR!=1'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-vE</span> <span style="color: #ff0000;">'LV|N/A'</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Create array of all filesystem sizes in volume group</span>
<span style="color: #007800;">count</span>=<span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #007800;">$count</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #800000;">${#fsname[*]}</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span>
           fssize<span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #007800;">$count</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">df</span> -v<span style="color: #007800;">$SIZE</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${fsname[$count]}</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'NR!=1'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ print $3 }'</span><span style="color: #000000; font-weight: bold;">`</span>
        <span style="color: #7a0874; font-weight: bold;">let</span> <span style="color: #007800;">count</span>=<span style="color: #ff0000;">&quot;count + 1&quot;</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;"># Array loop to print FS and SIZE</span>
<span style="color: #007800;">count</span>=<span style="color: #000000;">0</span>
<span style="color: #7a0874; font-weight: bold;">printf</span> <span style="color: #ff0000;">&quot;%-30s %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #660033;">----------</span> <span style="color: #660033;">-------</span>
<span style="color: #7a0874; font-weight: bold;">printf</span> <span style="color: #ff0000;">&quot;%-30s %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> Filesystem Size-<span style="color: #007800;">$SIZEB</span>
<span style="color: #7a0874; font-weight: bold;">printf</span> <span style="color: #ff0000;">&quot;%-30s %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #660033;">----------</span> <span style="color: #660033;">-------</span>
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #007800;">$count</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #800000;">${#fsname[*]}</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span>
           <span style="color: #7a0874; font-weight: bold;">printf</span> <span style="color: #ff0000;">&quot;%-30s %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #800000;">${fsname[$count]}</span> <span style="color: #800000;">${fssize[$count]}</span>
        <span style="color: #7a0874; font-weight: bold;">let</span> <span style="color: #007800;">count</span>=<span style="color: #ff0000;">&quot;count + 1&quot;</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Calculate totals</span>
<span style="color: #007800;">TOTAL</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${fssize[*]}</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'BEGIN {RS=&quot; &quot;} {SUM+=$1} END {print SUM}'</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
&nbsp;
<span style="color: #7a0874; font-weight: bold;">printf</span> <span style="color: #ff0000;">&quot;%-30s %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #660033;">-----</span> <span style="color: #660033;">--------</span>
<span style="color: #7a0874; font-weight: bold;">printf</span> <span style="color: #ff0000;">&quot;%-30s %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> Total <span style="color: #007800;">$TOTAL</span>
<span style="color: #7a0874; font-weight: bold;">printf</span> <span style="color: #ff0000;">&quot;%-30s %s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> <span style="color: #660033;">-----</span> <span style="color: #660033;">--------</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></div></div>

<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>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">root@AIX / &gt; vgusage
USAGE: /usr/bin/vgusage [k|m|g] [vg]</pre></div></div>

<p>Script being run on the data volume group with the output in GB blocks.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">root@AIX / &gt; 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></div></div>

<p>As always, post any questions to the comments.</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://www.kristijan.org/2010/05/calculate-total-usage-in-aix-volume-group/feed/</wfw:commentRss>
		<slash:comments>2</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  [...]]]></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>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/ksh </span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Maintain the last 1000 lines in /var/adm/wtmp</span>
<span style="color: #666666; font-style: italic;"># and discard the rest.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>adm<span style="color: #000000; font-weight: bold;">/</span>wtmp <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span> 
   <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>acct<span style="color: #000000; font-weight: bold;">/</span>fwtmp <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>adm<span style="color: #000000; font-weight: bold;">/</span>wtmp <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>wtmp.tmp 
   <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">tail</span> <span style="color: #660033;">-1000</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>wtmp.tmp <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>acct<span style="color: #000000; font-weight: bold;">/</span>fwtmp <span style="color: #660033;">-ic</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>adm<span style="color: #000000; font-weight: bold;">/</span>wtmp 
   <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>wtmp.tmp
<span style="color: #000000; font-weight: bold;">else</span> 
   <span style="color: #7a0874; font-weight: bold;">continue</span> 
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>Run it out of crontab nightly or whenever suits you.</p>
<!-- PHP 5.x -->]]></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>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/ksh</span>
&nbsp;
<span style="color: #007800;">dsmadmc</span>=<span style="color: #ff0000;">&quot;/usr/bin/dsmadmc -id=username -pass=password -dataonly=yes -displ=lis&quot;</span>
<span style="color: #007800;">count</span>=<span style="color: #000000;">0</span>
<span style="color: #007800;">zero</span>=00
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;The following tapes do not exist in TSM:&quot;</span>
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #007800;">$count</span> <span style="color: #000000; font-weight: bold;">&lt;</span>= <span style="color: #000000;">120</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$count</span> <span style="color: #660033;">-gt</span> <span style="color: #000000;">9</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">let</span> <span style="color: #007800;">zero</span>=<span style="color: #000000;">0</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$count</span> <span style="color: #660033;">-gt</span> <span style="color: #000000;">99</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">unset</span> zero
        <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
        <span style="color: #007800;">$dsmadmc</span> q volume ???<span style="color: #800000;">${zero}</span><span style="color: #800000;">${count}</span>?? <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> COL<span style="color: #800000;">${zero}</span><span style="color: #800000;">${count}</span>L4
        <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
        <span style="color: #7a0874; font-weight: bold;">let</span> <span style="color: #007800;">count</span>=<span style="color: #ff0000;">&quot;count + 1&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">done</span>
<span style="color: #7a0874; font-weight: bold;">exit</span></pre></div></div>

<!-- PHP 5.x -->]]></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  [...]]]></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>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/usr/bin/ksh</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># This script reports filesystem usages for</span>
<span style="color: #666666; font-style: italic;"># all mounted filesystems.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Filesystems can be excluded by editing the</span>
<span style="color: #666666; font-style: italic;"># SKIPFS variable e.g. SKIPFS='/proc|/test|/home'</span>
&nbsp;
<span style="color: #007800;">MAIL</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>mail
<span style="color: #007800;">RCPT</span>=<span style="color: #ff0000;">'your@email.com'</span>
<span style="color: #007800;">USAGE</span>=<span style="color: #000000;">80</span>
<span style="color: #007800;">HOSTNAME</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">hostname</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">SKIPFS</span>=<span style="color: #ff0000;">'/proc|/test'</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #660033;">-A</span> fs <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">df</span> <span style="color: #660033;">-k</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-vE</span> <span style="color: #007800;">$SKIPFS</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ print $4 }'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'NR!=1'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/%//'</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">set</span> <span style="color: #660033;">-A</span> fn <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">df</span> <span style="color: #660033;">-k</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-vE</span> <span style="color: #007800;">$SKIPFS</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ print $7 }'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'NR!=1'</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #007800;">count</span>=<span style="color: #000000;">0</span>
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #007800;">$count</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #800000;">${#fs[*]}</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>; <span style="color: #000000; font-weight: bold;">do</span>
        <span style="color: #007800;">fssize</span>=<span style="color: #800000;">${fs[$count]}</span>
        <span style="color: #000000; font-weight: bold;">if</span>
                <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$fssize</span> <span style="color: #660033;">-ge</span> <span style="color: #007800;">$USAGE</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${fn[$count]}</span> on <span style="color: #007800;">$HOSTNAME</span> is at <span style="color: #007800;">${fssize}</span>%&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #007800;">$MAIL</span> <span style="color: #660033;">-s</span> <span style="color: #ff0000;">&quot;WARNING on <span style="color: #007800;">$HOSTNAME</span>&quot;</span> <span style="color: #007800;">$RCPT</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
        <span style="color: #7a0874; font-weight: bold;">let</span> <span style="color: #007800;">count</span>=<span style="color: #ff0000;">&quot;count + 1&quot;</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exit</span></pre></div></div>

<!-- PHP 5.x -->]]></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>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  [...]]]></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.<br />
<span id="more-86"></span><br />
<strong><u>Splitting the file</u></strong></p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">kristijan@slackware testing$ ls -lh
total 13M
-rw-rw-r--  1 kristijan users 13M Jul 23 18:18 karaoke.mp3</pre></div></div>

<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:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">kristijan@slackware testing$ split -b 1945k karaoke.mp3</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">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></div></div>

<p>OK, what we have now done is told &#8216;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 &#8216;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>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">kristijan@slackware testing$ cat xa* &gt; karaoke-restored.mp3</pre></div></div>

<p>(Note** Before removing the original file, I recommend that you make a backup of it)</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">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* &gt; 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></div></div>

<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>
<!-- PHP 5.x -->]]></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 read all  [...]]]></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.<br />
<span id="more-71"></span><br />
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>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Script to send files to Windows workstations</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># set -x</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> runPingCheck <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-vE</span> <span style="color: #ff0000;">'^$|^#'</span> callcentres<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$name</span>.txt <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> i
        <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #c20cb9; font-weight: bold;">ping</span> <span style="color: #660033;">-c</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$i</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1}'</span><span style="color: #000000; font-weight: bold;">`</span>.fqdn.com <span style="color: #000000; font-weight: bold;">&amp;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-gt</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
                        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$i</span> ... PING FAIL&quot;</span>
                <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">done</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Check complete&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Continue with send(Y/N) [Y]? &quot;</span>
	<span style="color: #c20cb9; font-weight: bold;">read</span> contsend
		<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$contsend</span>&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
			N<span style="color: #000000; font-weight: bold;">|</span>n<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">;;</span>
			Y<span style="color: #000000; font-weight: bold;">|</span>y<span style="color: #000000; font-weight: bold;">|*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> runSendFiles <span style="color: #000000; font-weight: bold;">;;</span>
		<span style="color: #000000; font-weight: bold;">esac</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> runSendFiles <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Send started <span style="color: #780078;">`date`</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tee</span> <span style="color: #660033;">-a</span> <span style="color: #007800;">$name</span>.log
&nbsp;
	<span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-vE</span> <span style="color: #ff0000;">'^$|^#'</span> callcentres<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$name</span>.txt <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> i
        <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #c20cb9; font-weight: bold;">ping</span> <span style="color: #660033;">-c</span> <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$i</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1}'</span><span style="color: #000000; font-weight: bold;">`</span>.fqdn.com <span style="color: #000000; font-weight: bold;">&amp;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-gt</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
                        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$i</span> ... Host Offline&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tee</span> <span style="color: #660033;">-a</span> <span style="color: #007800;">$name</span>.log
                        <span style="color: #7a0874; font-weight: bold;">continue</span>
                <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
                <span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #660033;">-t</span> cifs <span style="color: #000000; font-weight: bold;">//`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$i</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1}'</span><span style="color: #000000; font-weight: bold;">`</span>.fqdn.com<span style="color: #000000; font-weight: bold;">/</span>c$ <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>winmnt <span style="color: #660033;">-o</span> <span style="color: #007800;">user</span>=administrator,<span style="color: #007800;">pass</span>=PASSHERE
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-gt</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
                        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$i</span> ... Failed CIFS Mount&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tee</span> <span style="color: #660033;">-a</span> <span style="color: #007800;">$name</span>.log
                <span style="color: #000000; font-weight: bold;">else</span>
                        <span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-R</span> .<span style="color: #000000; font-weight: bold;">/</span>files<span style="color: #000000; font-weight: bold;">/*</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>winmnt
                                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-e</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>winmnt<span style="color: #000000; font-weight: bold;">/</span>sent.tmp <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
                                        <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>winmnt<span style="color: #000000; font-weight: bold;">/</span>sent.tmp
                                        <span style="color: #c20cb9; font-weight: bold;">umount</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>winmnt
                                        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$i</span> ... Complete&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tee</span> <span style="color: #660033;">-a</span> <span style="color: #007800;">$name</span>.log
                                <span style="color: #000000; font-weight: bold;">else</span>
                                        <span style="color: #c20cb9; font-weight: bold;">umount</span> <span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>winmnt
                                        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$i</span> ... Failed File Verification&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tee</span> <span style="color: #660033;">-a</span> <span style="color: #007800;">$name</span>.log
                                <span style="color: #000000; font-weight: bold;">fi</span>
                <span style="color: #000000; font-weight: bold;">fi</span>
        <span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Send completed <span style="color: #780078;">`date`</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tee</span> <span style="color: #660033;">-a</span> <span style="color: #007800;">$name</span>.log
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">ls</span> .<span style="color: #000000; font-weight: bold;">/</span>callcentres <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/.txt//g'</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Type the name of the call centre you wish to upgrade: &quot;</span>
<span style="color: #c20cb9; font-weight: bold;">read</span> name
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Would you like to run a ping check before you send(Y/N) [Y]? &quot;</span>
<span style="color: #c20cb9; font-weight: bold;">read</span> pingcheck
&nbsp;
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$pingcheck</span>&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
	N<span style="color: #000000; font-weight: bold;">|</span>n<span style="color: #7a0874; font-weight: bold;">&#41;</span> runSendFiles <span style="color: #000000; font-weight: bold;">;;</span>
	Y<span style="color: #000000; font-weight: bold;">|</span>y<span style="color: #000000; font-weight: bold;">|*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> runPingCheck <span style="color: #000000; font-weight: bold;">;;</span>
<span style="color: #000000; font-weight: bold;">esac</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></div></div>

<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>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">host1
#host2
host3
...
host100</pre></div></div>

<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>
<!-- PHP 5.x -->]]></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!<br />
<span id="more-62"></span><br />
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>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Script to unrar season packs of TV shows</span>
<span style="color: #666666; font-style: italic;"># Put it in the directory containing all the directorys</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># eg.</span>
<span style="color: #666666; font-style: italic;">#       Big_Bang_Theory.1x01.Pilot.DVDRip_XviD-FoV/</span>
<span style="color: #666666; font-style: italic;">#       Big_Bang_Theory.1x02.The_Big_Bran_Hypothesis.DVDRip_XviD-FoV/</span>
<span style="color: #666666; font-style: italic;">#       Big_Bang_Theory.1x03.The_Fuzzy_Boots_Corollary.DVDRip_XviD-FoV/</span>
<span style="color: #666666; font-style: italic;">#       unrar_all</span>
&nbsp;
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-type</span> d <span style="color: #660033;">-print</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> i
        <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #7a0874; font-weight: bold;">pushd</span> .
        <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #007800;">$i</span>
                <span style="color: #7a0874; font-weight: bold;">unset</span> partrar
                <span style="color: #007800;">partrar</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-name</span> <span style="color: #000000; font-weight: bold;">*</span>part01.rar<span style="color: #000000; font-weight: bold;">`</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$partrar</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
                unrar e <span style="color: #000000; font-weight: bold;">*</span>part01.rar
                <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #000000; font-weight: bold;">*</span>.avi ..<span style="color: #000000; font-weight: bold;">/</span>
                <span style="color: #7a0874; font-weight: bold;">popd</span>
        <span style="color: #000000; font-weight: bold;">else</span>
                unrar e <span style="color: #000000; font-weight: bold;">*</span>.rar
                <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #000000; font-weight: bold;">*</span>.avi ..<span style="color: #000000; font-weight: bold;">/</span>
                <span style="color: #7a0874; font-weight: bold;">popd</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>This script requires <a href="http://www.rarlab.com/rar_add.htm">unrar</a> from RARLabs.</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://www.kristijan.org/2008/12/unrar-tv-show-packs/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

