<?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>Admins Goodies &#187; bash</title>
	<atom:link href="http://adminsgoodies.com/tag/bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://adminsgoodies.com</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Fri, 24 May 2013 16:33:10 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Recursively delete empty folders with verbose output</title>
		<link>http://adminsgoodies.com/recursively-delete-empty-folders-with-verbose-output/</link>
		<comments>http://adminsgoodies.com/recursively-delete-empty-folders-with-verbose-output/#comments</comments>
		<pubDate>Sun, 14 Apr 2013 16:33:19 +0000</pubDate>
		<dc:creator>tom</dc:creator>
				<category><![CDATA[General Questions]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[find]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[shell-scripting]]></category>

		<guid isPermaLink="false">http://adminsgoodies.com/recursively-delete-empty-folders-with-verbose-output/</guid>
		<description><![CDATA[This should be fairly simple, but I am not sure what i&#8217;m missing. I&#8217;d like to recursively delete empty directories, and get an output for what&#8217;s being deleted, this command works for sure, but I just can&#8217;t print the actions of -excec verbosely. while [ -n "$(find . -depth -type d -empty -exec rm -v -rf {} +)" ]; do :; done by recursively I mean, I want to keep deleting empty folders, until there&#8217;s [...]]]></description>
				<content:encoded><![CDATA[<h3 class="pq"><img src="http://adminsgoodies.com/imgs/question.png" alt="Question" /></h3>
<p>This should be fairly simple, but I am not sure what i&#8217;m missing.</p>
<p>I&#8217;d like to <strong>recursively</strong> delete empty directories, and get an output for what&#8217;s being deleted, this command works for sure, but I just can&#8217;t print the actions of -excec verbosely. </p>
<p><code>while [ -n "$(find . -depth -type d -empty -exec rm -v -rf {} +)" ]; do :; done</code></p>
<p>by <strong>recursively</strong> I mean, I want to keep deleting empty folders, until there&#8217;s no other empty folder. </p>
<pre class="prettyprint"><code>$ tree .
.
├── empty
│   └── empty
│       └── empty
└── non-emty
    └── ko
</code></pre>
<p>this item will only remove one empty folder in the tree</p>
<pre class="prettyprint"><code>$ find . -depth -type d -empty -exec rmdir -v {} +
rmdir: removing directory, `./empty/empty'
</code></pre>
<div class="author">Asked by <a href="http://serverfault.com/users/128156/kmassada" target="_blank">kmassada</a></div>
<h3 class="pa"><img src="http://adminsgoodies.com/imgs/answer.png" alt="Answer" /></h3>
<p>You don&#8217;t need the while loop and you should use rmdir -p to remove the empty parents</p>
<pre class="prettyprint"><code>find . -depth -type d -empty -exec rmdir -v -p {} + 
rmdir: removing directory, `./1/3'
rmdir: removing directory, `./1'
rmdir: removing directory, `.'
rmdir: failed to remove directory `.': Invalid argument
rmdir: removing directory, `./2/3'
rmdir: removing directory, `./2'
rmdir: failed to remove directory `./2': Directory not empty
</code></pre>
<p>The reason you don&#8217;t see the output with your command is that you are running it in a subshell <code>$(...)</code> but doing nothing with the returned output you could put an echo before the subsell to print out what it returns</p>
<pre class="prettyprint"><code>echo $(find . -depth -type d -empty -exec rmdir -v -p {} +)
rmdir: removing directory, `./1/3' rmdir: removing directory, `./1' rmdir: removing directory, `.' rmdir: removing directory, `./2/3' rmdir: removing directory, `./2'
</code></pre>
<div class="author">Answered by <a href="http://serverfault.com/users/9517/iain" target="_blank">Iain</a></div>
<p class="ref-link">Check <a href="http://serverfault.com/questions/499209/recursively-delete-empty-folders-with-verbose-output" target="_blank">more discussion</a> of this question.</p>
]]></content:encoded>
			<wfw:commentRss>http://adminsgoodies.com/recursively-delete-empty-folders-with-verbose-output/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding a timestamp to bash script log</title>
		<link>http://adminsgoodies.com/adding-a-timestamp-to-bash-script-log/</link>
		<comments>http://adminsgoodies.com/adding-a-timestamp-to-bash-script-log/#comments</comments>
		<pubDate>Sun, 03 Feb 2013 17:33:39 +0000</pubDate>
		<dc:creator>tom</dc:creator>
				<category><![CDATA[General Questions]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://adminsgoodies.com/adding-a-timestamp-to-bash-script-log/</guid>
		<description><![CDATA[I have a constantly running script that I output to a log file: script.sh &#62;&#62; /var/log/logfile I&#8217;d like to add a timestamp before each line that is appended to the log. Like: Sat Sep 10 21:33:06 UTC 2011 The server has booted up. Hmmph. Is there any jujitsu I can use? Asked by Antonius Bloch You can pipe the script&#8217;s output through a loop that prefixes the current date and time: ./script.sh &#124; while IFS= [...]]]></description>
				<content:encoded><![CDATA[<h3 class="pq"><img src="http://adminsgoodies.com/imgs/question.png" alt="Question" /></h3>
<p>I have a constantly running script that I output to a log file:</p>
<p>script.sh &gt;&gt; /var/log/logfile</p>
<p>I&#8217;d like to add a timestamp before each line that is appended to the log.  Like:</p>
<p>Sat Sep 10 21:33:06 UTC 2011 The server has booted up.  Hmmph.</p>
<p>Is there any jujitsu I can use?</p>
<div class="author">Asked by <a href="http://serverfault.com/users/66603/antonius-bloch" target="_blank">Antonius Bloch</a></div>
<h3 class="pa"><img src="http://adminsgoodies.com/imgs/answer.png" alt="Answer" /></h3>
<p>You can pipe the script&#8217;s output through a loop that prefixes the current date and time:</p>
<pre class="prettyprint"><code>./script.sh | while IFS= read -r line; do echo "$(date) $line"; done &gt;&gt;/var/log/logfile
</code></pre>
<p>If you&#8217;ll be using this a lot, it&#8217;s easy to make a bash function to handle the loop:</p>
<pre class="prettyprint"><code>adddate() {
    while IFS= read -r line; do
        echo "$(date) $line"
    done
}./thisscript.sh | adddate &gt;&gt;/var/log/logfile
./thatscript.sh | adddate &gt;&gt;/var/log/logfile
./theotherscript.sh | adddate &gt;&gt;/var/log/logfile
</code></pre>
<div class="author">Answered by <a href="http://serverfault.com/users/6621/gordon-davisson" target="_blank">Gordon Davisson</a></div>
<p class="ref-link">Check <a href="http://serverfault.com/questions/310098/adding-a-timestamp-to-bash-script-log" target="_blank">more discussion</a> of this question.</p>
]]></content:encoded>
			<wfw:commentRss>http://adminsgoodies.com/adding-a-timestamp-to-bash-script-log/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bash, running a command as an argument with arguments, and the continuing the original command</title>
		<link>http://adminsgoodies.com/bash-running-a-command-as-an-argument-with-arguments-and-the-continuing-the-original-command/</link>
		<comments>http://adminsgoodies.com/bash-running-a-command-as-an-argument-with-arguments-and-the-continuing-the-original-command/#comments</comments>
		<pubDate>Wed, 23 Jan 2013 17:34:34 +0000</pubDate>
		<dc:creator>tom</dc:creator>
				<category><![CDATA[General Questions]]></category>
		<category><![CDATA[bash]]></category>

		<guid isPermaLink="false">http://adminsgoodies.com/bash-running-a-command-as-an-argument-with-arguments-and-the-continuing-the-original-command/</guid>
		<description><![CDATA[Sorry for the very confusing title, but here&#8217;s what im trying to do: TORQUEBOX_START="$TORQUEBOX_HOME/jboss/bin/standalone.sh" TORQUEBOX_START_ARGS="--server-config=standalone-ha.xml"start-stop-daemon --start --quiet --chuid $DAEMONUSER \ --exec "${TORQUEBOX_START}" -- ${TORQUEBOX_START_ARGS} --pidfile $PIDFILE --make-pidfile -- -c $TORQUEBOX_SERVER &#62;&#62; $LOGFILE 2&#62;&#38;1 &#38; I need to run the TORQUEBOX_START with its arguments in the &#8211;exec argument. I tried using &#8212; to pass the args to it. But from there I dont really know how i can pop back to passing args to the original [...]]]></description>
				<content:encoded><![CDATA[<h3 class="pq"><img src="http://adminsgoodies.com/imgs/question.png" alt="Question" /></h3>
<p>Sorry for the very confusing title, but here&#8217;s what im trying to do: </p>
<pre class="prettyprint"><code> TORQUEBOX_START="$TORQUEBOX_HOME/jboss/bin/standalone.sh"
 TORQUEBOX_START_ARGS="--server-config=standalone-ha.xml"start-stop-daemon --start --quiet --chuid  $DAEMONUSER  \
  --exec "${TORQUEBOX_START}" -- ${TORQUEBOX_START_ARGS}  --pidfile $PIDFILE --make-pidfile -- -c $TORQUEBOX_SERVER &gt;&gt; $LOGFILE 2&gt;&amp;1 &amp;
</code></pre>
<p>I need to run the TORQUEBOX_START with its arguments in the &#8211;exec argument. I tried using &#8212; to pass the args to it. But from there I dont really know how i can pop back to passing args to the original command. The <code>--pidfile</code> for example needs to pass to <code>start-stop-daemon</code>. Is there a way to do this or a way you can suggest?</p>
<div class="author">Asked by <a href="http://serverfault.com/users/154428/agmcleod" target="_blank">agmcleod</a></div>
<h3 class="pa"><img src="http://adminsgoodies.com/imgs/answer.png" alt="Answer" /></h3>
<p>How about this?</p>
<pre class="prettyprint"><code>TORQUEBOX_START="$TORQUEBOX_HOME/jboss/bin/standalone.sh"
TORQUEBOX_START_ARGS="--server-config=standalone-ha.xml"start-stop-daemon \
  --start --quiet \
  --chuid $DAEMONUSER \
  --exec $TORQUEBOX_START \
  --pidfile $PIDFILE --make-pidfile \
  -- -c $TORQUEBOX_SERVER ${TORQUEBOX_START_ARGS} \
  &gt;&gt; $LOGFILE 2&gt;&amp;1
</code></pre>
<div class="author">Answered by <a href="http://serverfault.com/users/129323/fififox" target="_blank">Fififox</a></div>
<p class="ref-link">Check <a href="http://serverfault.com/questions/471409/bash-running-a-command-as-an-argument-with-arguments-and-the-continuing-the-or" target="_blank">more discussion</a> of this question.</p>
]]></content:encoded>
			<wfw:commentRss>http://adminsgoodies.com/bash-running-a-command-as-an-argument-with-arguments-and-the-continuing-the-original-command/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ordinary users are able to read /etc/passwd, is this a security hole?</title>
		<link>http://adminsgoodies.com/ordinary-users-are-able-to-read-etcpasswd-is-this-a-security-hole/</link>
		<comments>http://adminsgoodies.com/ordinary-users-are-able-to-read-etcpasswd-is-this-a-security-hole/#comments</comments>
		<pubDate>Wed, 23 Jan 2013 17:34:23 +0000</pubDate>
		<dc:creator>tom</dc:creator>
				<category><![CDATA[General Questions]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[root]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://adminsgoodies.com/ordinary-users-are-able-to-read-etcpasswd-is-this-a-security-hole/</guid>
		<description><![CDATA[ls -l /etc/passwd gives $ ls -l /etc/passwd -rw-r--r-- 1 root root 1862 2011-06-15 21:59 /etc/passwd So an ordinary user can read the file. Is this a security hole? Asked by abc Actual password hashes are stored in /etc/shadow, which is not readable by regular users. /etc/passwd holds other information about user ids and shells that must be readable by all users for the system to function. Answered by Michael Check more discussion of this [...]]]></description>
				<content:encoded><![CDATA[<h3 class="pq"><img src="http://adminsgoodies.com/imgs/question.png" alt="Question" /></h3>
<pre class="prettyprint"><code>ls -l /etc/passwd
</code></pre>
<p>gives</p>
<pre class="prettyprint"><code>$ ls -l /etc/passwd
-rw-r--r-- 1 root root 1862 2011-06-15 21:59 /etc/passwd
</code></pre>
<p>So an ordinary user can read the file. Is this a security hole?</p>
<div class="author">Asked by <a href="http://serverfault.com/users/78915/abc" target="_blank">abc</a></div>
<h3 class="pa"><img src="http://adminsgoodies.com/imgs/answer.png" alt="Answer" /></h3>
<p>Actual password hashes are stored in <code>/etc/shadow</code>, which is not readable by regular users.  <code>/etc/passwd</code> holds other information about user ids and shells that must be readable by all users for the system to function.</p>
<div class="author">Answered by <a href="http://serverfault.com/users/66038/michael" target="_blank">Michael</a></div>
<p class="ref-link">Check <a href="http://serverfault.com/questions/286654/ordinary-users-are-able-to-read-etc-passwd-is-this-a-security-hole" target="_blank">more discussion</a> of this question.</p>
]]></content:encoded>
			<wfw:commentRss>http://adminsgoodies.com/ordinary-users-are-able-to-read-etcpasswd-is-this-a-security-hole/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>escaping spaces in shell script</title>
		<link>http://adminsgoodies.com/escaping-spaces-in-shell-script/</link>
		<comments>http://adminsgoodies.com/escaping-spaces-in-shell-script/#comments</comments>
		<pubDate>Sat, 19 Jan 2013 17:34:22 +0000</pubDate>
		<dc:creator>tom</dc:creator>
				<category><![CDATA[General Questions]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[shell-script]]></category>
		<category><![CDATA[shell-scripting]]></category>

		<guid isPermaLink="false">http://adminsgoodies.com/escaping-spaces-in-shell-script/</guid>
		<description><![CDATA[yesterday="2010-06-23 00:00:00" today="2010-06-24 00:00:00" mywhere="lastupdate&#62;'$yesterday' and lastupdate&#60;'$today'"mysqldump $param ticket --no-create-info --where=\"$mywhere\" The last line of above shell script would return something like this&#8230; + mysqldump -uroot -d --compact ahmadpur ticket --no-create-info --where="lastupdate&#62;'2010-06-23 00:00:00' and lastupdate&#60;'2010-06-24 00:00:00'" mysqldump: Couldn't find table: "00:00:00'" There is an error in the mysqldump command execution. But if I copy paste the same line, it runs successfully. Do I need to escape the spaces in shell script output? if yes, how? [...]]]></description>
				<content:encoded><![CDATA[<h3 class="pq"><img src="http://adminsgoodies.com/imgs/question.png" alt="Question" /></h3>
<pre class="prettyprint"><code>yesterday="2010-06-23 00:00:00"
today="2010-06-24 00:00:00"
mywhere="lastupdate&gt;'$yesterday' and lastupdate&lt;'$today'"mysqldump $param ticket --no-create-info --where=\"$mywhere\"
</code></pre>
<p>The last line of above shell script would return something like this&#8230;</p>
<pre class="prettyprint"><code>+ mysqldump -uroot -d --compact ahmadpur ticket --no-create-info --where="lastupdate&gt;'2010-06-23 00:00:00' and lastupdate&lt;'2010-06-24 00:00:00'"
mysqldump: Couldn't find table: "00:00:00'"
</code></pre>
<p>There is an error in the mysqldump command execution. But if I copy paste the same line, it runs successfully.<br />
Do I need to escape the spaces in shell script output? if yes, how?</p>
<div class="author">Asked by <a href="http://serverfault.com/users/16842/shantanuo" target="_blank">shantanuo</a></div>
<h3 class="pa"><img src="http://adminsgoodies.com/imgs/answer.png" alt="Answer" /></h3>
<pre class="prettyprint"><code>mysqldump $param ticket --no-create-info --where="$mywhere"
</code></pre>
<p>(do not escape double quotes in <code>--where="$mywhere"</code>)</p>
<div class="author">Answered by <a href="http://serverfault.com/users/45368/zed-0xff" target="_blank">zed_0xff</a></div>
<p class="ref-link">Check <a href="http://serverfault.com/questions/470603/escaping-spaces-in-shell-script" target="_blank">more discussion</a> of this question.</p>
]]></content:encoded>
			<wfw:commentRss>http://adminsgoodies.com/escaping-spaces-in-shell-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>how to see process status with full details</title>
		<link>http://adminsgoodies.com/how-to-see-process-status-with-full-details/</link>
		<comments>http://adminsgoodies.com/how-to-see-process-status-with-full-details/#comments</comments>
		<pubDate>Wed, 16 Jan 2013 17:33:56 +0000</pubDate>
		<dc:creator>tom</dc:creator>
				<category><![CDATA[General Questions]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[ksh]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[process]]></category>
		<category><![CDATA[solaris]]></category>

		<guid isPermaLink="false">http://adminsgoodies.com/how-to-see-process-status-with-full-details/</guid>
		<description><![CDATA[I run the script &#8211; my_script.ksh as process with 5 long arguments on my solaris/linux machine ( example 1 ) , Later I verify the process by ps -ef &#124; grep my_script.ksh I don&#8217;t understand way I not get the all arguments from ps -ef ? , ( see example 2 ) or maybe ps command have limitation to display a long line ? , or maybe need to write the ps command with some [...]]]></description>
				<content:encoded><![CDATA[<h3 class="pq"><img src="http://adminsgoodies.com/imgs/question.png" alt="Question" /></h3>
<p>I run the script &#8211; <strong>my_script.ksh</strong> as process with 5 long arguments </p>
<p>on my solaris/linux machine ( example 1 ) , </p>
<p>Later I verify the process by </p>
<pre class="prettyprint"><code> ps -ef | grep  my_script.ksh 
</code></pre>
<p>I don&#8217;t understand way I not get the all arguments from <strong>ps -ef</strong> ? , ( see example 2 )</p>
<p>or maybe ps command have limitation to display a long line ? ,<br />
or maybe need to write the ps command with some flags that will<br />
enable to display all arguments ?</p>
<p>what need to do in order see all arguments from <strong>ps -ef</strong> command ? </p>
<p><strong>Example 1</strong> ( run <strong>my_script.ksh</strong> with the relevant arguments )</p>
<pre class="prettyprint"><code>           #  ( /tmp/my_script.ksh PATH1=/usr/lib/efcode/sparcv9/efdaemon PATH2=/etc/opt/VO/share/conf/nnmet/mib/Fore-pre802dot1Q-VLAN-MIB.mib -scan-files -ignore-simbolic-links -give-full-file-details ) &amp;
 [1]     18942
</code></pre>
<p><strong>Example 2</strong> ( verify script proccess , but can&#8217;t see all arguments ? )</p>
<pre class="prettyprint"><code>       # ps -ef | grep my_script.ksh 
root 18942 11889   0 13:22:20 pts/1       0:00 /bin/ksh /tmp/my_script.ksh PATH1=/usr/lib/efcode/sparcv9/efdaemon PATH2=/etc/o     
</code></pre>
<div class="author">Asked by <a href="http://serverfault.com/users/117906/yael" target="_blank">yael</a></div>
<h3 class="pa"><img src="http://adminsgoodies.com/imgs/answer.png" alt="Answer" /></h3>
<p>On Solaris, try using <code>/usr/ucb/ps -auxwww | grep my_script.sh</code> instead. This will show the full command line and arguments of the process.<br />
For Linux, simply use <code>ps aux</code>.</p>
<p>Also try experimenting with forcing certain fields only to be displayed by <code>ps</code>,<br />
e.g. <code>ps -ao comm,args</code> will display the command and its arguments.</p>
<p>A bit of time spent in <code>man ps</code> should get you on the right track.</p>
<div class="author">Answered by <a href="http://serverfault.com/users/52838/shaun-dewberry" target="_blank">Shaun Dewberry</a></div>
<p class="ref-link">Check <a href="http://serverfault.com/questions/469609/how-to-see-process-status-with-full-details" target="_blank">more discussion</a> of this question.</p>
]]></content:encoded>
			<wfw:commentRss>http://adminsgoodies.com/how-to-see-process-status-with-full-details/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cannot change chmod from bash script</title>
		<link>http://adminsgoodies.com/cannot-change-chmod-from-bash-script/</link>
		<comments>http://adminsgoodies.com/cannot-change-chmod-from-bash-script/#comments</comments>
		<pubDate>Wed, 09 Jan 2013 17:34:01 +0000</pubDate>
		<dc:creator>tom</dc:creator>
				<category><![CDATA[General Questions]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://adminsgoodies.com/cannot-change-chmod-from-bash-script/</guid>
		<description><![CDATA[I made a script to copy an image to a temporary directory, convert it to an another format, then move it to a final directory. But i can&#8217;t get the chmod command to work, the file is copied to the temporary directory but it&#8217;s chmod is stuck on -rw&#8212;&#8212;- (the original chmod of the file). If i apply a 777 chmod on the original file, the copied one get a -rwx&#8212;&#8212; instead of a -rwxrwxrwx [...]]]></description>
				<content:encoded><![CDATA[<h3 class="pq"><img src="http://adminsgoodies.com/imgs/question.png" alt="Question" /></h3>
<p>I made a script to copy an image to a temporary directory, convert it to an another format, then move it to a final directory.<br />
But i can&#8217;t get the chmod command to work, the file is copied to the temporary directory but it&#8217;s chmod is stuck on -rw&#8212;&#8212;- (the original chmod of the file).</p>
<p>If i apply a 777 chmod on the original file, the copied one get a -rwx&#8212;&#8212; instead of a -rwxrwxrwx</p>
<p>The copied and orignal files have the same user.</p>
<pre class="prettyprint"><code>TS=$(date +"%Y")/$(date +"%m")/$(date +"%d")/$(date +"%Hh%Ms%S")
PATHTMP="/tmp/faxtiff"mkdir -p $PATHTMP
chmod 777 $PATHTMP
cp $FILE $PATHTMP
chmod 777 $PATHTMP/$FILE
convert $PATHTMP/$FILE -scale '50%x100%!' $PATHTMP/fax.jpg
chmod 777 $PATHTMP/fax.jpg
mkdir -p /home/argent/faxes-recus/$TS
chmod 777 /home/argent/faxes-recus/$TS
#rm $PATHTMP/$FILE
mv $PATHTMP/*.jpg /home/argent/faxes-recus/$TS
</code></pre>
<div class="author">Asked by <a href="http://serverfault.com/users/106550/doesnotcompute" target="_blank">DoesNotCompute</a></div>
<h3 class="pa"><img src="http://adminsgoodies.com/imgs/answer.png" alt="Answer" /></h3>
<p>mdpc is correct. I don&#8217;t know why somebody downvoted your question, but&#8230;</p>
<p>If root owns the file, you should be able (assuming you have access of course) to do a <code>sudo chmod...</code>, and that should work.</p>
<p>If, however, you don&#8217;t want root to own the file anymore, you&#8217;ll need to do a <code>sudo chown $USER &lt;filename&gt;</code> to cause the file to be owned by the user you are logged in as.</p>
<p>I haven&#8217;t tried your script, but go ahead and try the following, noting 2 things:</p>
<p>1) Don&#8217;t go around chowning things that you shouldn&#8217;t. I don&#8217;t know the context of this question, and it may be bad, very bad, or extremely extremely bad to chown the files in question (read: abuse of power). However, if you are creating this content and are implicitly (or explicitly) being given permission to mod these files, then it shouldn&#8217;t be a problem.</p>
<p>2) I commented out a couple chowns that you shouldn&#8217;t need. Remember, you can always do a <code>ls -l</code> to see the ownership of a given file.</p>
<pre class="prettyprint"><code>TS=$(date +"%Y")/$(date +"%m")/$(date +"%d")/$(date +"%Hh%Ms%S")
PATHTMP="/tmp/faxtiff"mkdir -p $PATHTMP
#sudo chown -R $USER $PATHTMP 
chmod 777 $PATHTMP
cp $FILE $PATHTMP
sudo chown $PATHTMP/$FILE
chmod 777 $PATHTMP/$FILE
convert $PATHTMP/$FILE -scale '50%x100%!' $PATHTMP/fax.jpg
#shouldn't need to chown here if the script is being run as the logged in user.
chmod 777 $PATHTMP/fax.jpg
mkdir -p /home/argent/faxes-recus/$TS
#chown $USER /home/argent/faxes-recus/$TS
chmod 777 /home/argent/faxes-recus/$TS
#rm $PATHTMP/$FILE
mv $PATHTMP/*.jpg /home/argent/faxes-recus/$TS
</code></pre>
<div class="author">Answered by <a href="http://serverfault.com/users/151827/cody-s" target="_blank">Cody S</a></div>
<p class="ref-link">Check <a href="http://serverfault.com/questions/464152/cannot-change-chmod-from-bash-script" target="_blank">more discussion</a> of this question.</p>
]]></content:encoded>
			<wfw:commentRss>http://adminsgoodies.com/cannot-change-chmod-from-bash-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Escaping special characters while sourcing file in bash</title>
		<link>http://adminsgoodies.com/escaping-special-characters-while-sourcing-file-in-bash/</link>
		<comments>http://adminsgoodies.com/escaping-special-characters-while-sourcing-file-in-bash/#comments</comments>
		<pubDate>Mon, 07 Jan 2013 17:33:36 +0000</pubDate>
		<dc:creator>tom</dc:creator>
				<category><![CDATA[General Questions]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[escape]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://adminsgoodies.com/escaping-special-characters-while-sourcing-file-in-bash/</guid>
		<description><![CDATA[I&#8217;v written a script that sources a bash shell fragment. The shell fragment is supposed to be a kind of configuration file, basically it&#8217;s a bunch of bash variable. The issue here is when some of those string variable contain characters that should be escaped. As they aren&#8217;t escape, the script might faill later on or have undesired behavior. At the moment, my script is validating the shell fragment (the configuration file) bash syntax (bash [...]]]></description>
				<content:encoded><![CDATA[<h3 class="pq"><img src="http://adminsgoodies.com/imgs/question.png" alt="Question" /></h3>
<p>I&#8217;v written a script that sources a bash shell fragment. The shell fragment is supposed to be a kind of configuration file, basically it&#8217;s a bunch of bash variable.</p>
<p>The issue here is when some of those string variable contain characters that should be escaped. As they aren&#8217;t escape, the script might faill later on or have undesired behavior.</p>
<p>At the moment, my script is validating the shell fragment (the configuration file) bash syntax (bash -n) but if any charachter is to be escaped, that won&#8217;t be detected.</p>
<p>So, I would like either to auto-escape sensitive character or, at least, detect their are some so I can display an error and exit.</p>
<p>Any idea how could I achieve that?</p>
<p>Thanks in advance,</p>
<div class="author">Asked by <a href="http://serverfault.com/users/152368/user152368" target="_blank">user152368</a></div>
<h3 class="pa"><img src="http://adminsgoodies.com/imgs/answer.png" alt="Answer" /></h3>
<p>The <code>$?</code> variable is your friend. It contains the return status of the most recently executed command, including bash built-in functions.</p>
<pre class="prettyprint"><code>$ /bin/false
$ echo $?
1
$ /bin/true
$ echo $?
0
$ echo 'FOO="bar' &gt; atest
$ . atest
-bash: atest: line 1: unexpected EOF while looking for matching `"'
-bash: atest: line 2: syntax error: unexpected end of file
$ echo $?
1
</code></pre>
<p>Keep in mind that it only returns the status of the most <strong>recent</strong> command. If you need to run an additional command before performing your error test, you need to immediately assign it to a variable like so:</p>
<pre class="prettyprint"><code>$ /bin/false
$ MYRETURN=$?
$ /bin/true
$ echo $?
0
$ echo $MYRETURN
1
</code></pre>
<div class="author">Answered by <a href="http://serverfault.com/users/152073/andrew-b" target="_blank">Andrew B</a></div>
<p class="ref-link">Check <a href="http://serverfault.com/questions/463701/escaping-special-characters-while-sourcing-file-in-bash" target="_blank">more discussion</a> of this question.</p>
]]></content:encoded>
			<wfw:commentRss>http://adminsgoodies.com/escaping-special-characters-while-sourcing-file-in-bash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Running drupal as root in order for it to run bash scripts</title>
		<link>http://adminsgoodies.com/running-drupal-as-root-in-order-for-it-to-run-bash-scripts/</link>
		<comments>http://adminsgoodies.com/running-drupal-as-root-in-order-for-it-to-run-bash-scripts/#comments</comments>
		<pubDate>Tue, 01 Jan 2013 17:33:41 +0000</pubDate>
		<dc:creator>tom</dc:creator>
				<category><![CDATA[General Questions]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[redhat]]></category>

		<guid isPermaLink="false">http://adminsgoodies.com/running-drupal-as-root-in-order-for-it-to-run-bash-scripts/</guid>
		<description><![CDATA[I store a website on redhat and using drupal. There is a button on the site that activates a php script and that php script use exec to activate bash script on the server. Right now the script is not being run, i guess because of permission reason &#8211; the drupal user that runs the bash does not have root access to run the bash script. How can i add the user as a root [...]]]></description>
				<content:encoded><![CDATA[<h3 class="pq"><img src="http://adminsgoodies.com/imgs/question.png" alt="Question" /></h3>
<p>I store a website on redhat and using drupal.<br />
There is a button on the site that activates a php script and that php script use exec to activate bash script on the server.<br />
Right now the script is not being run, i guess because of permission reason &#8211; the drupal user that runs the bash does not have root access to run the bash script.<br />
How can i add the user as a root and test this ? and then to downgrade it to normal level.<br />
So what i need to know &#8211; how to view current users, groups, and status, and changing them.  </p>
<p>Is this recommended ? I am not linux expert.  </p>
<p>Thanks.</p>
<div class="author">Asked by <a href="http://serverfault.com/users/127185/ilansch" target="_blank">ilansch</a></div>
<h3 class="pa"><img src="http://adminsgoodies.com/imgs/answer.png" alt="Answer" /></h3>
<p>You don&#8217;t need to run your web server (like apache) as root to do this. You can instead allow sudo for the web server user without password. To do so, edit the sudoers file using:</p>
<pre class="prettyprint"><code>$ sudo visudo
</code></pre>
<p>and insert a line like this:</p>
<pre class="prettyprint"><code>www-data ALL=NOPASSWD: /path/to/your/script
</code></pre>
<p>The above line assumes the web server user name is <code>www-data</code>. You need to change it as appropriate.</p>
<div class="author">Answered by <a href="http://serverfault.com/users/58024/khaled" target="_blank">Khaled</a></div>
<p class="ref-link">Check <a href="http://serverfault.com/questions/462078/running-drupal-as-root-in-order-for-it-to-run-bash-scripts" target="_blank">more discussion</a> of this question.</p>
]]></content:encoded>
			<wfw:commentRss>http://adminsgoodies.com/running-drupal-as-root-in-order-for-it-to-run-bash-scripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>linux + create Shortcut command</title>
		<link>http://adminsgoodies.com/linux-create-shortcut-command/</link>
		<comments>http://adminsgoodies.com/linux-create-shortcut-command/#comments</comments>
		<pubDate>Mon, 31 Dec 2012 17:33:31 +0000</pubDate>
		<dc:creator>tom</dc:creator>
				<category><![CDATA[General Questions]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[ksh]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[shell-scripting]]></category>

		<guid isPermaLink="false">http://adminsgoodies.com/linux-create-shortcut-command/</guid>
		<description><![CDATA[I am not sure if I performed the following illegal or true but what I need is &#8211; to create set of ready commands so if I need to use , for example to match IP address with 4 octet I can use the command &#8211; command_that_match_four_octet Please advice if I performed correctly the following and, I want to know if the following syntax will not cause troubles. [root@su1a /tmp]# command_that_match_four_octet=" grep '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' "[root@su1a /tmp]# [...]]]></description>
				<content:encoded><![CDATA[<h3 class="pq"><img src="http://adminsgoodies.com/imgs/question.png" alt="Question" /></h3>
<p>I am not sure if I performed the following illegal or true </p>
<p>but what I need is &#8211; to create set of ready commands<br />
so if I need to use , for example to match IP address with 4 octet<br />
I can use the command &#8211;  <strong>command_that_match_four_octet</strong></p>
<p>Please advice if I performed correctly the following and, I want to know if the following syntax will not cause troubles.</p>
<pre class="prettyprint"><code>[root@su1a /tmp]#  command_that_match_four_octet=" grep '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' "[root@su1a /tmp]# command_that_match_three_three_octet=" grep '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' "
</code></pre>
<p>.</p>
<pre class="prettyprint"><code>[root@su1a /tmp]# echo 23.4.5.1  | eval $command_that_match_four_octet
   23.4.5.1[root@su1a /tmp]# echo 23.4.5 | eval $command_that_match_three_three_octet
   23.4.5
</code></pre>
<div class="author">Asked by <a href="http://serverfault.com/users/117906/yael" target="_blank">yael</a></div>
<h3 class="pa"><img src="http://adminsgoodies.com/imgs/answer.png" alt="Answer" /></h3>
<p>what you call <code>shortcut</code> seem to be a kind of <code>alias</code> or more complex <code>functions</code>.</p>
<p>for answering you ask, you could:</p>
<pre class="prettyprint"><code>alias checkCommand="grep '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'"
echo 23.4.5.1  | checkCommand
23.4.5.1
</code></pre>
<p>or</p>
<pre class="prettyprint"><code>function checkIsIp() {
    grep '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'
}
echo 23.4.5.1  | checkIsIp
</code></pre>
<p>There is a bash function that will check for IP (v4) and more this will compute 32bit integer if argument is a valid IP and return a <code>RC &gt; 0</code> if else:</p>
<pre class="prettyprint"><code>function check_Is_Ip() {
    local IFS=.
    set -- $1
    [ $# -eq 4 ] || return 2
    local var
    for var in $* ;do
        [ $var -lt 0 ] || [ $var -gt 255 ] &amp;&amp; return 3
      done
    echo $(( ($1&lt;&lt;24) + ($2&lt;&lt;16) + ($3&lt;&lt;8) + $4))
}
</code></pre>
<p>than now:</p>
<pre class="prettyprint"><code>if check_Is_Ip 1.0.0.1 &gt;/dev/null; then echo It is. ;else echo There is not. ;fi
It is.if check_Is_Ip 1.255.0.1 &gt;/dev/null; then echo It is. ;else echo There is not. ;fi
It is.if check_Is_Ip 1.256.0.1 &gt;/dev/null; then echo It is. ;else echo There is not. ;fi
There is not.
</code></pre>
<p>and useable for IP calculation:</p>
<p>There is the back function:</p>
<pre class="prettyprint"><code>int2ip() {
    echo $(($1&gt;&gt;24)).$(($1&gt;&gt;16&amp;255)).$(($1&gt;&gt;8&amp;255)).$(($1&amp;255))
}check_Is_Ip 255.255.255.0
4294967040
check_Is_Ip 192.168.1.31
3232235807int2ip $((4294967040 &amp; 3232235807))
192.168.1.0
</code></pre>
<p>So as a good practice, you could:</p>
<pre class="prettyprint"><code>function die() {
    echo "Error: $@" &gt;&amp;2
    exit 1
}netIp="192.168.1.31"
netMask="255.255.255.0"intIp=$(check_Is_Ip $netIp) || die "Submited IP: '$netIP' is not an IPv4 address."
intMask=$(check_Is_Ip $netMask) || die "Submited Mask: '$netMask' not IPv4."
netBase=$(int2ip $(( intIp &amp; intMask )) )
netBcst=$(int2ip $(( intIp | intMask ^ ( (1&lt;&lt;32) - 1 ) )) )
printf "%-20s: %s\n" \
    Address $netIp Netmask $netMask Network $netBase Broadcast $netBcstAddress             : 192.168.1.31
Netmask             : 255.255.255.0
Network             : 192.168.1.0
Broadcast           : 192.168.1.255
</code></pre>
<p>Where check, validation and conversion of inputs are done is only one operation:</p>
<pre class="prettyprint"><code>intMask=$(check_Is_Ip $netMask) || die "Submited Mask: '$netMask' not IPv4."
</code></pre>
<p>If <code>$netMask</code> don&#8217;t match IPv4, the command <code>check_Is_Ip</code> will fail, then <code>die</code> will be executed. If else, result of conversion will be stored in <code>intMask</code> variable.</p>
<div class="author">Answered by <a href="http://serverfault.com/users/142978/f-hauri" target="_blank">F. Hauri</a></div>
<p class="ref-link">Check <a href="http://serverfault.com/questions/461760/linux-create-shortcut-command" target="_blank">more discussion</a> of this question.</p>
]]></content:encoded>
			<wfw:commentRss>http://adminsgoodies.com/linux-create-shortcut-command/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
