<?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; Quan Tran</title>
	<atom:link href="https://qtran.info/category/scripting-tips/bash-scripts/feed/" rel="self" type="application/rss+xml" />
	<link>https://qtran.info</link>
	<description></description>
	<lastBuildDate>Wed, 17 Oct 2018 07:33:44 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>

<image>
	<url>https://qtran.info/wp-content/uploads/2018/10/cropped-logo-2-32x32.jpg</url>
	<title>Bash &#8211; Quan Tran</title>
	<link>https://qtran.info</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>POST Json message to server</title>
		<link>https://qtran.info/post-json-message-to-server/</link>
		
		<dc:creator><![CDATA[quan3t]]></dc:creator>
		<pubDate>Wed, 17 Oct 2018 07:28:45 +0000</pubDate>
				<category><![CDATA[Bash]]></category>
		<guid isPermaLink="false"></guid>

					<description><![CDATA[Send a POST to a Json server #!/bin/bash BOT_SERVICE=&#8221;http://bots.json.com&#8221; message=$(cat &#60;&#60;EOF { &#8220;to&#8221;:&#8221;test@test.com&#8221;, &#8220;from&#8221;:&#8221;test@test.com&#8221;, &#8220;html&#8221;:&#8221;&#60;font color=&#8217;red&#8217;&#62;Am a bot.&#60;/font&#62;&#8221; } EOF ) curl -i -X POST -H &#8220;Content-Type: application/json&#8221; -d &#8220;$message&#8221; $BOT_SERVICE Can also read in a file and format that as the message #!/bin/bash bot_input=&#8221;bot_input.txt&#8221; BOT_SERVICE=&#8221;http://bots.json.com&#8221; html_input=$(&#60;$bot_input) message=$(cat &#60;&#60;EOF { &#8220;to&#8221;:&#8221;test@test.com&#8221;, &#8220;from&#8221;:&#8221;test@test.com&#8221;, &#8220;html&#8221;:&#8221;$html_input&#8221; } EOF ) curl -i -X POST -H &#8220;Content-Type: application/json&#8221; -d &#8220;$message&#8221; $BOT_SERVICE]]></description>
										<content:encoded><![CDATA[<p>Send a POST to a Json server</p>
<blockquote><p>#!/bin/bash<br />
BOT_SERVICE=&#8221;http://bots.json.com&#8221;</p>
<p>message=$(cat &lt;&lt;EOF<br />
{<br />
&#8220;to&#8221;:&#8221;test@test.com&#8221;,<br />
&#8220;from&#8221;:&#8221;test@test.com&#8221;,<br />
&#8220;html&#8221;:&#8221;&lt;font color=&#8217;red&#8217;&gt;Am a bot.&lt;/font&gt;&#8221;<br />
}<br />
EOF<br />
)<br />
curl -i -X POST -H &#8220;Content-Type: application/json&#8221; -d &#8220;$message&#8221; $BOT_SERVICE</p></blockquote>
<p>Can also read in a file and format that as the message</p>
<blockquote><p>#!/bin/bash</p>
<p>bot_input=&#8221;bot_input.txt&#8221;<br />
BOT_SERVICE=&#8221;http://bots.json.com&#8221;</p>
<p>html_input=$(&lt;$bot_input)</p>
<p>message=$(cat &lt;&lt;EOF<br />
{<br />
&#8220;to&#8221;:&#8221;test@test.com&#8221;,<br />
&#8220;from&#8221;:&#8221;test@test.com&#8221;,<br />
&#8220;html&#8221;:&#8221;$html_input&#8221;<br />
}<br />
EOF<br />
)<br />
curl -i -X POST -H &#8220;Content-Type: application/json&#8221; -d &#8220;$message&#8221; $BOT_SERVICE</p></blockquote>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SSH to multiple servers using Expect</title>
		<link>https://qtran.info/ssh-to-multiple-servers-using-expect/</link>
		
		<dc:creator><![CDATA[quan3t]]></dc:creator>
		<pubDate>Wed, 17 Oct 2018 07:24:50 +0000</pubDate>
				<category><![CDATA[Bash]]></category>
		<guid isPermaLink="false"></guid>

					<description><![CDATA[Script will login to multiple servers and perform certain command automatically. Requires an input file of format HostName:IP:Pass #!/bin/bash # Require an input.txt file with the format of CLLI:IP:Pass # This scirpt will add the RSA key for lss user if [ -e &#8220;input.txt&#8221; ]; then while read i; do /usr/bin/expect &#60;(cat &#60;&#60; EOD set timeout 15 spawn ssh &#8220;user@$(echo $i &#124; cut -d: -f 2)&#8221; ####################### expect &#8220;yes/no&#8221; { send &#8220;yes\r&#8221; expect &#8220;Password:&#8221; { send {$(echo $i &#124; cut [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Script will login to multiple servers and perform certain command automatically.</p>
<p>Requires an input file of format HostName:IP:Pass</p>
<blockquote><p>#!/bin/bash<br />
# Require an input.txt file with the format of CLLI:IP:Pass<br />
# This scirpt will add the RSA key for lss user</p>
<p>if [ -e &#8220;input.txt&#8221; ]; then<br />
while read i; do</p>
<p>/usr/bin/expect &lt;(cat &lt;&lt; EOD<br />
set timeout 15<br />
spawn ssh &#8220;user@$(echo $i | cut -d: -f 2)&#8221;<br />
#######################</p>
<p>expect &#8220;yes/no&#8221; {<br />
send &#8220;yes\r&#8221;<br />
expect &#8220;Password:&#8221; { send {$(echo $i | cut -d: -f 3)}; send \r }<br />
} &#8220;Password:&#8221; { send {$(echo $i | cut -d: -f 3)}; send \r }<br />
expect -re &#8220;day: $&#8221; { send &#8220;\r&#8221; }<br />
expect &#8220;:&#8221; { send &#8220;\r&#8221; }<br />
expect -re &#8220;# $&#8221; { send &#8220;ll\r&#8221; }<br />
expect -re &#8220;# $&#8221; { send &#8220;mkdir .ssh\r&#8221; }<br />
expect -re &#8220;# $&#8221; { send &#8220;cd .ssh\r&#8221; }<br />
expect -re &#8220;# $&#8221; { send &#8220;touch authorized_keys\r&#8221; }<br />
expect -re &#8220;# $&#8221; { send &#8220;chmod 700 authorized_keys\r&#8221; }<br />
expect -re &#8220;# $&#8221; { send &#8220;echo &#8216;ssh-rsa KEY&#8217; &gt;&gt; authorized_keys\r&#8221; }<br />
expect -re &#8220;# $&#8221; { send &#8220;cat authorized_keys\r&#8221; }<br />
expect -re &#8220;# $&#8221; { send &#8220;exit\r&#8221; }<br />
EOD<br />
)<br />
done &lt; input.txt<br />
fi</p></blockquote>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Sendmail sample</title>
		<link>https://qtran.info/sendmail-sample/</link>
		
		<dc:creator><![CDATA[quan3t]]></dc:creator>
		<pubDate>Wed, 17 Oct 2018 07:20:07 +0000</pubDate>
				<category><![CDATA[Bash]]></category>
		<guid isPermaLink="false"></guid>

					<description><![CDATA[Sendmail script passing in a file as message. File have filename format test.hostname.network #!/bin/bash mailserver=&#8217;test@test.com&#8217; for f in $* do m=$( echo $f &#124; cut -d. -f2 ) mail -s &#8220;XML file from $m&#8221; $mailserver &#60; $f done You execute the script as such ./sample_script.sh filename ./sample_script.sh test*                    # execute for all files begin with test in directory]]></description>
										<content:encoded><![CDATA[<p>Sendmail script passing in a file as message. File have filename format test.hostname.network</p>
<blockquote><p>#!/bin/bash</p>
<p>mailserver=&#8217;test@test.com&#8217;<br />
for f in $*<br />
do<br />
m=$( echo $f | cut -d. -f2 )<br />
mail -s &#8220;XML file from $m&#8221; $mailserver &lt; $f<br />
done</p></blockquote>
<p>You execute the script as such</p>
<blockquote><p>./sample_script.sh filename</p>
<p>./sample_script.sh test*                    # execute for all files begin with test in directory</p></blockquote>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Download from multiple servers using SCP</title>
		<link>https://qtran.info/download-from-multiple-servers-using-scp/</link>
		
		<dc:creator><![CDATA[quan3t]]></dc:creator>
		<pubDate>Wed, 17 Oct 2018 07:06:33 +0000</pubDate>
				<category><![CDATA[Bash]]></category>
		<guid isPermaLink="false"></guid>

					<description><![CDATA[Script allow you to download from multiple servers using SCP protocol and sshpass to send password for authentication. Files will be stored in different directory with hostname. Requires an input file with format HostName:IP:Pass if [ -e &#8220;input.txt&#8221; ]; then while read i; do mkdir &#8220;$(echo $i &#124; cut -d: -f 1)&#8221; echo &#8220;$(echo $i &#124; cut -d: -f 3)&#8221; &#62; pass.txt sshpass -f &#8220;pass.txt&#8221; scp -o StrictHostkeyChecking=no user@&#8221;$(echo $i &#124; cut -d: -f 2)&#8221;:/tmp/*sample &#8220;./$(echo $i&#124;cut -d: -f 1)&#8221; [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Script allow you to download from multiple servers using SCP protocol and sshpass to send password for authentication. Files will be stored in different directory with hostname.</p>
<p>Requires an input file with format HostName:IP:Pass</p>
<blockquote><p>if [ -e &#8220;input.txt&#8221; ]; then<br />
while read i; do<br />
mkdir &#8220;$(echo $i | cut -d: -f 1)&#8221;<br />
echo &#8220;$(echo $i | cut -d: -f 3)&#8221; &gt; pass.txt<br />
sshpass -f &#8220;pass.txt&#8221; scp -o StrictHostkeyChecking=no user@&#8221;$(echo $i | cut -d: -f 2)&#8221;:/tmp/*sample &#8220;./$(echo $i|cut -d: -f 1)&#8221;<br />
done &lt; input.txt<br />
fi</p>
<p>rm pass.txt</p></blockquote>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
