<?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>bash &#8211; Uroš Vovk</title>
	<atom:link href="https://www.urosvovk.com/tag/bash/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.urosvovk.com</link>
	<description>Uroš Vovk home page</description>
	<lastBuildDate>Mon, 28 Oct 2013 16:47:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>
	<item>
		<title>Temporary Disabling Bash History</title>
		<link>https://www.urosvovk.com/temporary-disabling-bash-history/</link>
		
		<dc:creator><![CDATA[Uroš]]></dc:creator>
		<pubDate>Mon, 28 Oct 2013 16:47:53 +0000</pubDate>
				<category><![CDATA[Linux Stuff]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[bash history]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[commands]]></category>
		<category><![CDATA[disable]]></category>
		<guid isPermaLink="false">http://www.urosvovk.com/?p=640</guid>

					<description><![CDATA[Let&#8217;s assume that you want execute some command that you don&#8217;t want in your history (e.g. commands with  passwords), but you don&#8217;t want to clear your entire history because of these. all you need to do is to run the following command: unset HISTFILE or HISTFILE=/dev/null this will disable history for your current session.]]></description>
										<content:encoded><![CDATA[<p>Let&#8217;s assume that you want execute some command that you don&#8217;t want in your history (e.g. commands with  passwords), but you don&#8217;t want to clear your entire history because of these.</p>
<p>all you need to do is to run the following command:</p>
<pre>unset HISTFILE</pre>
<p>or</p>
<pre>HISTFILE=/dev/null</pre>
<p>this will disable history for your current session.</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Backup (from command line)/Restore OpenFiler</title>
		<link>https://www.urosvovk.com/backup-openfiler-from-command-line/</link>
		
		<dc:creator><![CDATA[Uroš]]></dc:creator>
		<pubDate>Tue, 21 Feb 2012 08:50:24 +0000</pubDate>
				<category><![CDATA[Linux Stuff]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[openfiler]]></category>
		<category><![CDATA[restore]]></category>
		<guid isPermaLink="false">http://urosv.wordpress.com/?p=165</guid>

					<description><![CDATA[Backup Openfiler When I need a Openfiler backup for the first time, I did this: 1. Log in OpenFiler Web UI 2. Click System 3. Click Backup/Restore 4. Click Download This works well if you have time to do this steps every day&#8230; but if you don&#8217;t want to do this steps every day, you &#8230; <a href="https://www.urosvovk.com/backup-openfiler-from-command-line/" class="more-link">Continue reading <span class="screen-reader-text">Backup (from command line)/Restore OpenFiler</span></a>]]></description>
										<content:encoded><![CDATA[<h2>Backup Openfiler</h2>
<p>When I need a Openfiler backup for the first time, I did this:</p>
<p>1. Log in OpenFiler Web UI<br />
2. Click System<br />
3. Click Backup/Restore<br />
4. Click Download</p>
<p>This works well if you have time to do this steps every day&#8230; but if you don&#8217;t want to do this steps every day, you must find another way to do daily backups&#8230;</p>
<p>After my little research, I find out that when I click on Backup/Restore, Openfiler cal this file: https://openfiler:446/admin/system_backup.html</p>
<p>I examined the content of this file and finded out, that all you need to backup your OpenFiler configuration is this:<br />
<span id="more-165"></span></p>
<pre>
export LANG=C; /usr/bin/sudo grep /mnt/ /etc/fstab &gt; /opt/openfiler/etc/fstab_mnt
export LANG=C; /usr/bin/sudo /bin/tar --ignore-failed-read -cPpzf / --exclude /opt/openfiler/etc/httpd/logs --exclude /opt/openfiler/etc/update.log /opt/openfiler/etc/</pre>
<p>After that, I created a script to put in my crontab, which backup Openfiler configuration every day. I keep only backups newer then 7 dasy, older backups are deleted.</p>
<h3>Here is my script</h3>
<pre>
BCKNAME="OpenFiler_`hostname`_`date "+%Y-%d-%m"`.tgz"
BCKFOLDER="/root/backup"
BCKCNT=`ls -1 $BCKFOLDER/OpenFiler_* | grep -c OpenFiler_`

function bck {
	export LANG=C; /usr/bin/sudo grep /mnt/ /etc/fstab &gt; /opt/openfiler/etc/fstab_mnt
	export LANG=C; /usr/bin/sudo /bin/tar --ignore-failed-read -cPpzf $1 --exclude /opt/openfiler/etc/httpd/logs --exclude /opt/openfiler/etc/update.log /opt/openfiler/etc/
}

cd $BCKFOLDER

if [ $BCKCNT -gt 7 ];
then
	ls -tr -1 OpenFiler_*.tgz | tail -n 8 | head -n1 | xargs -I{} find $BCKFOLDER -name "OpenFiler_*.tgz" -not -newer {} | xargs rm
	bck $BCKFOLDER/$BCKNAME
else
	bck $BCKFOLDER/$BCKNAME
fi</pre>
<h3>How it works</h3>
<p>This is a backup name (like OpenFiler_UrosOF_2012-21-02.tgz)</p>
<pre>
BCKNAME="OpenFiler_`hostname`_`date "+%Y-%d-%m"`.tgz"</pre>
<p>Backup destination</p>
<pre>
BCKFOLDER="/root/backup"</pre>
<p>This count backups already in backup folder</p>
<pre>
BCKCNT=`ls -1 $BCKFOLDER/OpenFiler_* | grep -c OpenFiler_`</pre>
<p>Function to export all OpenFiler configuration files.<br />
$1 -&gt; function parameter: backup location/name</p>
<pre>
function bck {
	export LANG=C; /usr/bin/sudo grep /mnt/ /etc/fstab &gt; /opt/openfiler/etc/fstab_mnt
	export LANG=C; /usr/bin/sudo /bin/tar --ignore-failed-read -cPpzf $1 --exclude /opt/openfiler/etc/httpd/logs --exclude /opt/openfiler/etc/update.log /opt/openfiler/etc/
}</pre>
<p>Change directory to backup directory and check if backup folder contains more than 7 backups, if yes remove older backups and create a new one, else just create a new backup</p>
<pre>
cd $BCKFOLDER
if [ $BCKCNT -gt 7 ];
then
	ls -tr -1 OpenFiler_*.tgz | tail -n 8 | head -n1 | xargs -I{} find $BCKFOLDER -name "OpenFiler_*.tgz" -not -newer {} | xargs rm
	bck $BCKFOLDER/$BCKNAME
else
	bck $BCKFOLDER/$BCKNAME
fi</pre>
<h2>Restore Openfiler</h2>
<p>1. Log in OpenFiler Web UI<br />
2. Click System<br />
3. Click Backup/Restore<br />
4. Browse to your backup file<br />
5. Click Upload</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Power on/off script for Xen Running VMs on XenServer</title>
		<link>https://www.urosvovk.com/power-onoff-script-for-xen-running-vms-on-xenserver/</link>
					<comments>https://www.urosvovk.com/power-onoff-script-for-xen-running-vms-on-xenserver/#comments</comments>
		
		<dc:creator><![CDATA[Uroš]]></dc:creator>
		<pubDate>Mon, 20 Feb 2012 12:05:57 +0000</pubDate>
				<category><![CDATA[Linux Stuff]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[power off]]></category>
		<category><![CDATA[power on]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[shutdown]]></category>
		<category><![CDATA[Virtual machines]]></category>
		<category><![CDATA[VM]]></category>
		<category><![CDATA[xenserver]]></category>
		<guid isPermaLink="false">http://urosv.wordpress.com/?p=153</guid>

					<description><![CDATA[Days ago I needed a script to power on/off my runing VMs on XenServer&#8230; In my case I needed this to power off VMs when my UPS is running on batery and later to power on when the power comes back. I was looking for a script that can do the job, but after a &#8230; <a href="https://www.urosvovk.com/power-onoff-script-for-xen-running-vms-on-xenserver/" class="more-link">Continue reading <span class="screen-reader-text">Power on/off script for Xen Running VMs on XenServer</span></a>]]></description>
										<content:encoded><![CDATA[<p>Days ago I needed a script to power on/off my runing VMs on XenServer&#8230; In my case I needed this to power off VMs when my UPS is running on batery and later to power on when the power comes back.</p>
<p>I was looking for a script that can do the job, but after a while I didn&#8217;t find anything usefull&#8230; so I made my own script&#8230;<br />
<span id="more-153"></span><br />
My idea was to create a list of all running VMs and power off this VMs. Later, when I need to power on this VMs (from the list) I just call the same script again and it turn on all my VMs that are on this list.</p>
<p>Here is my script (shutdown_xen_vm.sh):</p>
<pre>#!/bin/bash

PROGRAMPATH="/root/scr/shutdown_vm"
if [ -f $PROGRAMPATH/vm-list.txt ]
then
   #$PROGRAMPATH/vm-list.txt exist
   echo "Power on:"
   cat $PROGRAMPATH/vm-list.txt | xargs -I{} echo " - {}"
   cat $PROGRAMPATH/vm-list.txt | xargs -I{} xe vm-start vm={}
   echo "Done"
   rm $PROGRAMPATH/vm-list.txt
else
   #$PROGRAMPATH/vm-list.txt do not exist
   xe vm-list power-state=running | grep name-label | awk '{print $4}' | tac | head -n -1 &gt; $PROGRAMPATH/vm-list.txt
   echo "Power off:"
   cat $PROGRAMPATH/vm-list.txt | xargs -I{} echo " - {}"
   cat $PROGRAMPATH/vm-list.txt | xargs -I{} xe vm-shutdown vm={}
   echo "Done"
   echo "Shutdown xen server..."
   shutdown -P now
fi</pre>
<h2>How it works:</h2>
<p>check if file vm-list.txt exist</p>
<pre>   if [ -f $PROGRAMPATH/vm-list.txt ]</pre>
<p>Just print a list of all VMs that were powered off</p>
<pre>   echo "Power on:"
   cat $PROGRAMPATH/vm-list.txt | xargs -I{} echo " - {}"</pre>
<p>Start all VMs from the list and delete this list</p>
<pre>   cat $PROGRAMPATH/vm-list.txt | xargs -I{} xe vm-start vm={}
   echo "Done"
   rm $PROGRAMPATH/vm-list.txt</pre>
<p>Get all running VMs and write it to vm-list.txt</p>
<pre>xe vm-list power-state=running | grep name-label | awk '{print $4}' | tac | head -n -1 &gt; /root/scr/shutdown_vm/vm-list.txt</pre>
<p>Just print a list of all VMs that will be powered off</p>
<pre>   echo "Power off:"
   cat $PROGRAMPATH/vm-list.txt | xargs -I{} echo " - {}"</pre>
<p>Power off VMs from the list and shutdown XenServer</p>
<pre>   
   cat $PROGRAMPATH/vm-list.txt | xargs -I{} xe vm-shutdown vm={}
   echo "Done"
   echo "Shutdown xen server..."
   shutdown -P now</pre>
<p>Now, to run this script you just need to do this:</p>
<pre>   
chmod +x shutdown_xen_vm.sh
./shutdown_xen_vm.sh</pre>
<p>&#8212;</p>
<p>I hope that this script will help you as it helped me :)</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.urosvovk.com/power-onoff-script-for-xen-running-vms-on-xenserver/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
