<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: basic shell scripting .. help needed in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/basic-shell-scripting-help-needed/m-p/4641631#M41012</link>
    <description>thank you .. there is a long way to go before i understand scripting well.. for a system admin i should know perl n shell well .. like in this case i dont understand even what &lt;BR /&gt;if [ -d /home/$1 ]&lt;BR /&gt;-d means in this case...&lt;BR /&gt;&lt;BR /&gt;thanks again</description>
    <pubDate>Thu, 03 Jun 2010 10:20:11 GMT</pubDate>
    <dc:creator>iinfi1</dc:creator>
    <dc:date>2010-06-03T10:20:11Z</dc:date>
    <item>
      <title>basic shell scripting .. help needed</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-shell-scripting-help-needed/m-p/4641628#M41009</link>
      <description>well i v jus started to learn scripting through some videos i have. is tldp.org/LDP/abs/html  a good site to learn scripting? any other better place??&lt;BR /&gt;&lt;BR /&gt;i was following a script to check the space occupied by each user in their home directory.&lt;BR /&gt;I have users u1 u2 u3&lt;BR /&gt;[code]&lt;BR /&gt;linux-lw75:~/scripts # cat spaceloop.sh&lt;BR /&gt;#!/bin/bash&lt;BR /&gt;#This script determines the size of a user's home directory&lt;BR /&gt;&lt;BR /&gt;if [ $# -lt 1 ]&lt;BR /&gt;then&lt;BR /&gt;        echo "you must pass atleast one argument to the $0 script"&lt;BR /&gt;        exit&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;while [ $# -ge 1 ]&lt;BR /&gt;do&lt;BR /&gt;        cd /home/$1&lt;BR /&gt;        space=`du -s | cut -f 1`&lt;BR /&gt;        echo "$1 is using $space kilobytes"&lt;BR /&gt;        shift&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;linux-lw75:~/scripts # sh spaceloop.sh u1 u2[color=red] u10 [/color]u3&lt;BR /&gt;u1 is using 1680 kilobytes&lt;BR /&gt;u2 is using 100 kilobytes&lt;BR /&gt;spaceloop.sh: line 12: cd: /home/u10: No such file or directory&lt;BR /&gt;u10 is using 100 kilobytes&lt;BR /&gt;u3 is using 100 kilobytes&lt;BR /&gt;linux-lw75:~/scripts #&lt;BR /&gt;&lt;BR /&gt;[/code]&lt;BR /&gt;&lt;BR /&gt;the above script runs fine when the parameters provided are correct ... eg in the above case when i provided 'u10' (which is not present in the system), the script could not handle it. What statement included above "space=`du -s | cut -f 1`" can catch the error "spaceloop.sh: line 12: cd: /home/u10: No such file or directory"&lt;BR /&gt;&lt;BR /&gt;thanks ...</description>
      <pubDate>Wed, 02 Jun 2010 22:56:26 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-shell-scripting-help-needed/m-p/4641628#M41009</guid>
      <dc:creator>iinfi1</dc:creator>
      <dc:date>2010-06-02T22:56:26Z</dc:date>
    </item>
    <item>
      <title>Re: basic shell scripting .. help needed</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-shell-scripting-help-needed/m-p/4641629#M41010</link>
      <description>Hi You need to put one more line in ur script to catch the error.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#!/bin/bash&lt;BR /&gt;#This script determines the size of a user's home directory&lt;BR /&gt;&lt;BR /&gt;if [ $# -lt 1 ]&lt;BR /&gt;then&lt;BR /&gt;echo "you must pass atleast one argument to the $0 script"&lt;BR /&gt;exit&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;while [ $# -ge 1 ]&lt;BR /&gt;do&lt;BR /&gt;if [ -d /home/$1 ]&lt;BR /&gt;cd /home/$1 2&amp;gt;/dev/null&lt;BR /&gt;then&lt;BR /&gt;space=`du -s | cut -f 1`&lt;BR /&gt;echo "$1 is using $space kilobytes"&lt;BR /&gt;fi&lt;BR /&gt;shift&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;, there are so many things you can do.&lt;BR /&gt;Best thing is to run scripts as &lt;BR /&gt;&lt;BR /&gt;spaceloop.sh -x u1 u2 u10&lt;BR /&gt;and it would tell you what exactly its happening and would help u in getting on the error.&lt;BR /&gt;&lt;BR /&gt;BR,&lt;BR /&gt;Kapil+</description>
      <pubDate>Thu, 03 Jun 2010 02:24:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-shell-scripting-help-needed/m-p/4641629#M41010</guid>
      <dc:creator>Kapil Jha</dc:creator>
      <dc:date>2010-06-03T02:24:15Z</dc:date>
    </item>
    <item>
      <title>Re: basic shell scripting .. help needed</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-shell-scripting-help-needed/m-p/4641630#M41011</link>
      <description>one trick to script troubleshooting.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Any error running script ??? go for debug option &lt;BR /&gt;&lt;BR /&gt;Modify shell definition to "#!/bin/bash -x" in script &lt;BR /&gt;&lt;BR /&gt;it will give clear out with commands executing &amp;amp; output of each commands... its a very easy method, you can troubleshoot any script with your own.&lt;BR /&gt;&lt;BR /&gt;Gudluck&lt;BR /&gt;Prasanth</description>
      <pubDate>Thu, 03 Jun 2010 06:24:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-shell-scripting-help-needed/m-p/4641630#M41011</guid>
      <dc:creator>Prasanth V Aravind</dc:creator>
      <dc:date>2010-06-03T06:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: basic shell scripting .. help needed</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-shell-scripting-help-needed/m-p/4641631#M41012</link>
      <description>thank you .. there is a long way to go before i understand scripting well.. for a system admin i should know perl n shell well .. like in this case i dont understand even what &lt;BR /&gt;if [ -d /home/$1 ]&lt;BR /&gt;-d means in this case...&lt;BR /&gt;&lt;BR /&gt;thanks again</description>
      <pubDate>Thu, 03 Jun 2010 10:20:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-shell-scripting-help-needed/m-p/4641631#M41012</guid>
      <dc:creator>iinfi1</dc:creator>
      <dc:date>2010-06-03T10:20:11Z</dc:date>
    </item>
    <item>
      <title>Re: basic shell scripting .. help needed</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-shell-scripting-help-needed/m-p/4641632#M41013</link>
      <description>hi,&lt;BR /&gt;&lt;BR /&gt;-d =&amp;gt; To check if a directory exists&lt;BR /&gt;&lt;BR /&gt;example :&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;To check if a directory exists in a bash shell script you can use the following:&lt;BR /&gt;&lt;BR /&gt;if [ -d "$DIRECTORY" ]; then&lt;BR /&gt;    # Control will enter here if $DIRECTORY exists&lt;BR /&gt;fi&lt;BR /&gt;Or to check if a directory doesn't exist:&lt;BR /&gt;&lt;BR /&gt;if [ ! -d "$DIRECTORY" ]; then&lt;BR /&gt;    # Control will enter here if $DIRECTORY doesn't exist&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;mikap&lt;BR /&gt;</description>
      <pubDate>Thu, 03 Jun 2010 11:24:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-shell-scripting-help-needed/m-p/4641632#M41013</guid>
      <dc:creator>Michal Kapalka (mikap)</dc:creator>
      <dc:date>2010-06-03T11:24:45Z</dc:date>
    </item>
    <item>
      <title>Re: basic shell scripting .. help needed</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-shell-scripting-help-needed/m-p/4641633#M41014</link>
      <description>hi,&lt;BR /&gt;&lt;BR /&gt;you oculd check this how-to as an example :&lt;BR /&gt;&lt;BR /&gt;"Linux/UNIX: Find Out If File Exists With Conditional Expressions"&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html" target="_blank"&gt;http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;mikap&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 03 Jun 2010 11:26:14 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-shell-scripting-help-needed/m-p/4641633#M41014</guid>
      <dc:creator>Michal Kapalka (mikap)</dc:creator>
      <dc:date>2010-06-03T11:26:14Z</dc:date>
    </item>
    <item>
      <title>Re: basic shell scripting .. help needed</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-shell-scripting-help-needed/m-p/4641634#M41015</link>
      <description>&lt;!--!*#--&gt;The fun thing about shell scripts, like any program, is error handling. If you can 100% guarantee the input, it's not a big deal, but that's normally not the case.&lt;BR /&gt;&lt;BR /&gt;Read the "bash" manpage, and feel free to post any questions here. If you want to find out the test flags, see the section for "test."&lt;BR /&gt;&lt;BR /&gt;Here's a short script that works on Cygwin to enumerate active users' home directories:&lt;BR /&gt;--&lt;BR /&gt;for f in $(cut -d: -f6 /etc/passwd); do&lt;BR /&gt;  # If it's a directory&lt;BR /&gt;  [[ -d "$f" ]] &amp;amp;&amp;amp; &lt;BR /&gt;       # Change over to that directory (in case it's a symlink)&lt;BR /&gt;    {  cd "$f"; &lt;BR /&gt;      # disk usage on current directory&lt;BR /&gt;      du -sh .; &lt;BR /&gt;      # Change back - probably not necessary, but why not?&lt;BR /&gt;      cd -;  }; &lt;BR /&gt;done&lt;BR /&gt;--&lt;BR /&gt;&lt;BR /&gt;If you want to deal with input, check out the "getopts" shell builtin that handles arguments. They're made so you don't have to re-implement a common need.</description>
      <pubDate>Thu, 03 Jun 2010 23:32:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-shell-scripting-help-needed/m-p/4641634#M41015</guid>
      <dc:creator>macosta</dc:creator>
      <dc:date>2010-06-03T23:32:52Z</dc:date>
    </item>
    <item>
      <title>Re: basic shell scripting .. help needed</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-shell-scripting-help-needed/m-p/4641635#M41016</link>
      <description>&amp;gt;&amp;gt;f [ -d /home/$1 ]&lt;BR /&gt;&amp;gt;&amp;gt;-d means in this case...&lt;BR /&gt;&lt;BR /&gt;iinfi, I think we can point out whats wrong where int he forum, we can not teach shell/perl script in the forum.&lt;BR /&gt;&lt;BR /&gt;Happy Learning!!&lt;BR /&gt;&lt;BR /&gt;BR,&lt;BR /&gt;Kapil+&lt;BR /&gt;</description>
      <pubDate>Fri, 04 Jun 2010 01:43:02 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-shell-scripting-help-needed/m-p/4641635#M41016</guid>
      <dc:creator>Kapil Jha</dc:creator>
      <dc:date>2010-06-04T01:43:02Z</dc:date>
    </item>
    <item>
      <title>Re: basic shell scripting .. help needed</title>
      <link>https://community.hpe.com/t5/operating-system-linux/basic-shell-scripting-help-needed/m-p/4641636#M41017</link>
      <description>hi all&lt;BR /&gt;&lt;BR /&gt;thanks a lot for  your help ... yea i do understand forum is a place to clear doubts and not learn from scratch ... &lt;BR /&gt;i am learning scripting now.. will post here if i have further doubts &lt;BR /&gt;thanks</description>
      <pubDate>Fri, 04 Jun 2010 07:25:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/basic-shell-scripting-help-needed/m-p/4641636#M41017</guid>
      <dc:creator>iinfi1</dc:creator>
      <dc:date>2010-06-04T07:25:03Z</dc:date>
    </item>
  </channel>
</rss>

