<?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: Shell script help needed in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help-needed/m-p/4497340#M680717</link>
    <description>&lt;!--!*#--&gt;Hi:&lt;BR /&gt;&lt;BR /&gt;Since you didn't present the whole script, it's hard to offer too many suggestions.&lt;BR /&gt;&lt;BR /&gt;However:&lt;BR /&gt;&lt;BR /&gt;Good practice declares the interpreter in the 'shebang' line as the first of the script:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;...for example.&lt;BR /&gt;&lt;BR /&gt;if [[ $1 == "-u" ]]&lt;BR /&gt;&lt;BR /&gt;...should be:&lt;BR /&gt;&lt;BR /&gt;if [[ $1 = "-u" ]]&lt;BR /&gt;&lt;BR /&gt;You can use loops to structure your script like this:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;typeset -i counter=0&lt;BR /&gt;echo "Enter directory name; CTL_D to quit"&lt;BR /&gt;while read directory&lt;BR /&gt;do&lt;BR /&gt;    [ -d "${directory}" ] || { echo "not a directory"; continue; }&lt;BR /&gt;    [ "$(ls -a ${directory} 2&amp;gt;/dev/null | wc -l)" -le 2 ] &amp;amp;&amp;amp; { echo "empty dir"; continue; }&lt;BR /&gt;    counter=$((counter+1))&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;The 'continue' statement restarts the loop and allow us to gracefully reject non-directories and directories that are empty.  The 'ls -a' causes the dot and dot-dot directories to be returned along with any "hidden" files (those that begin with a dot).  Hence, an empty directory is one with only two entries.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
    <pubDate>Tue, 15 Sep 2009 11:05:15 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2009-09-15T11:05:15Z</dc:date>
    <item>
      <title>Shell script help needed</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help-needed/m-p/4497337#M680714</link>
      <description>Hello, &lt;BR /&gt;&lt;BR /&gt;I am using a shell script which in turn calls a expect script to upload files to a remote server. My script is working files to upload the files, the only logic that I cannot get to work is when there are no files to upload to the remote server, I would like a check to be performed and a message to be displayed stating " There are no files to be uploaded".&lt;BR /&gt;&lt;BR /&gt;I am pasting part of my script.&lt;BR /&gt;&lt;BR /&gt;# Counters&lt;BR /&gt;uSuccess=0&lt;BR /&gt;uFailure=0&lt;BR /&gt;&lt;BR /&gt;cd $HOME&lt;BR /&gt;&lt;BR /&gt;if [[ $1 == "-u" ]]&lt;BR /&gt;then&lt;BR /&gt;echo "Uploading..."&lt;BR /&gt;&lt;BR /&gt;while read line&lt;BR /&gt;do&lt;BR /&gt;      # test&lt;BR /&gt;      upload_directory=${line}/submission/test&lt;BR /&gt;            &lt;BR /&gt;      directory=${HOME}/toupload/test/${line}&lt;BR /&gt;      cd ${directory}&lt;BR /&gt;      echo "in directory ${directory}"&lt;BR /&gt;&lt;BR /&gt;      counter=0&lt;BR /&gt;      for filename in *&lt;BR /&gt;      do&lt;BR /&gt;   &lt;BR /&gt;          if [[ -f ${filename} ]]&lt;BR /&gt;          then&lt;BR /&gt;&lt;BR /&gt;   let counter=counter+1&lt;BR /&gt;&lt;BR /&gt;          filename_abs=${directory}/${filename}&lt;BR /&gt;&lt;BR /&gt;          ${HOME}/ftp_upload.exp ${user} ${pword} ${host} ${upload_directory} ${filename}&lt;BR /&gt;&lt;BR /&gt;   &lt;BR /&gt;          if [[ $? -eq 0 ]] &lt;BR /&gt;          then&lt;BR /&gt;       &lt;BR /&gt;              echo "$(date): ${directory}/${filename} uploaded"  &amp;gt;&amp;gt; $LOGDIR/sftp_audit.log&lt;BR /&gt;              rm ${filename}&lt;BR /&gt;       let uSuccess=uSuccess+1&lt;BR /&gt;          else&lt;BR /&gt;                echo "$(date): ${directory}/${filename} not able to upload"  &amp;gt;&amp;gt; $LOGDIR/sftp_failure.log&lt;BR /&gt;       let uFailure=uFailure+1&lt;BR /&gt;          fi&lt;BR /&gt;          fi&lt;BR /&gt;      done&lt;BR /&gt;&lt;BR /&gt;      if [[ $counter -eq 0 ]]&lt;BR /&gt;      then&lt;BR /&gt; echo "$(date): No files to upload from ${directory} directory" &amp;gt;&amp;gt; $LOGDIR/sftp_audit.log&lt;BR /&gt;      fi</description>
      <pubDate>Tue, 15 Sep 2009 02:08:13 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help-needed/m-p/4497337#M680714</guid>
      <dc:creator>rhansen</dc:creator>
      <dc:date>2009-09-15T02:08:13Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script help needed</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help-needed/m-p/4497338#M680715</link>
      <description>Hi,&lt;BR /&gt;&amp;gt;&amp;gt;I cannot get to work is when there are no files to upload to the remote server, I would like a check to be performed and a message to be displayed stating " There are no files to be uploaded".&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Take a "ls -lrt &amp;gt; chkfile" now check if chkfile size is 0 that means there is no file to upload.&lt;BR /&gt;&lt;BR /&gt;Suraj</description>
      <pubDate>Tue, 15 Sep 2009 02:22:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help-needed/m-p/4497338#M680715</guid>
      <dc:creator>Suraj K Sankari</dc:creator>
      <dc:date>2009-09-15T02:22:06Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script help needed</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help-needed/m-p/4497339#M680716</link>
      <description>Just before getting into the for loop for uploading, you can perform a chack like this:&lt;BR /&gt;&lt;BR /&gt;filecount=`ls ${directory}|wc -c`&lt;BR /&gt;&lt;BR /&gt;if [ ${filecount} -eq 0 ]&lt;BR /&gt;then&lt;BR /&gt;echo "There is nothing to upload in ${directory}"&lt;BR /&gt;else&lt;BR /&gt;# go into the for loop here&lt;BR /&gt;# ...&lt;BR /&gt;# end of for loop and any other things &lt;BR /&gt;# you want to do before relinquishing control&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Hope this helps...</description>
      <pubDate>Tue, 15 Sep 2009 02:24:38 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help-needed/m-p/4497339#M680716</guid>
      <dc:creator>Mel Burslan</dc:creator>
      <dc:date>2009-09-15T02:24:38Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script help needed</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help-needed/m-p/4497340#M680717</link>
      <description>&lt;!--!*#--&gt;Hi:&lt;BR /&gt;&lt;BR /&gt;Since you didn't present the whole script, it's hard to offer too many suggestions.&lt;BR /&gt;&lt;BR /&gt;However:&lt;BR /&gt;&lt;BR /&gt;Good practice declares the interpreter in the 'shebang' line as the first of the script:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;&lt;BR /&gt;...for example.&lt;BR /&gt;&lt;BR /&gt;if [[ $1 == "-u" ]]&lt;BR /&gt;&lt;BR /&gt;...should be:&lt;BR /&gt;&lt;BR /&gt;if [[ $1 = "-u" ]]&lt;BR /&gt;&lt;BR /&gt;You can use loops to structure your script like this:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;typeset -i counter=0&lt;BR /&gt;echo "Enter directory name; CTL_D to quit"&lt;BR /&gt;while read directory&lt;BR /&gt;do&lt;BR /&gt;    [ -d "${directory}" ] || { echo "not a directory"; continue; }&lt;BR /&gt;    [ "$(ls -a ${directory} 2&amp;gt;/dev/null | wc -l)" -le 2 ] &amp;amp;&amp;amp; { echo "empty dir"; continue; }&lt;BR /&gt;    counter=$((counter+1))&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;The 'continue' statement restarts the loop and allow us to gracefully reject non-directories and directories that are empty.  The 'ls -a' causes the dot and dot-dot directories to be returned along with any "hidden" files (those that begin with a dot).  Hence, an empty directory is one with only two entries.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Tue, 15 Sep 2009 11:05:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help-needed/m-p/4497340#M680717</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-09-15T11:05:15Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script help needed</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help-needed/m-p/4497341#M680718</link>
      <description>As advised, I tried it but still does not work. I am pasting thq full section of my upload script.&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;# set -x&lt;BR /&gt;#&lt;BR /&gt;# Establish and set variables&lt;BR /&gt;host_id="xyz.test.org"&lt;BR /&gt;port_number="\#22"&lt;BR /&gt;user_id="abcd"&lt;BR /&gt;password="password"&lt;BR /&gt;HOME="/home/abcd"&lt;BR /&gt;TMP=${HOME}/tmp&lt;BR /&gt;LOGDIR="/var/adm/ras/"&lt;BR /&gt; &lt;BR /&gt;if [[ $# -ne 1 ]]&lt;BR /&gt;then&lt;BR /&gt;    echo "Usage script -u|-d"&lt;BR /&gt;    exit 1&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;if [[ $1 = "-u" ]]&lt;BR /&gt;then&lt;BR /&gt;echo "Upload"&lt;BR /&gt;while read line&lt;BR /&gt;do&lt;BR /&gt;      &lt;BR /&gt;      upload_directory=${line}/submission/test&lt;BR /&gt;      directory=${HOME}/upload/test/${line}&lt;BR /&gt;      cd ${directory}&lt;BR /&gt;      echo "in directory ${directory}"&lt;BR /&gt;      for filename in *&lt;BR /&gt;      do&lt;BR /&gt;          if [[ -f ${filename} ]]&lt;BR /&gt;          then&lt;BR /&gt;          filename_abs=${directory}/${filename}&lt;BR /&gt;          filecount=`ls ${directory}/wc -c`&lt;BR /&gt;          if [[ ${filecount} -eq 0 ]]&lt;BR /&gt;          then echo "There is nothing to upload in ${directory}"&lt;BR /&gt;          else&lt;BR /&gt;          ${HOME}/sftp.exp ${user_id} ${password} ${host_id} ${port_number} ${upload_directory} ${filename}&lt;BR /&gt;          if [[ $? -eq 0 ]]&lt;BR /&gt;          then&lt;BR /&gt;              echo "$(date): ${directory}/${filename} uploaded &amp;gt;&amp;gt; $LOGDIR/sftp_audit.log&lt;BR /&gt;              &lt;BR /&gt;          else&lt;BR /&gt;             &lt;BR /&gt;              echo "$(date): ${directory}/${filename} not able to upload &amp;gt;&amp;gt; $LOGDIR/sftp_failure.log&lt;BR /&gt;          fi&lt;BR /&gt;          fi&lt;BR /&gt;          fi&lt;BR /&gt;      done&lt;BR /&gt;</description>
      <pubDate>Wed, 16 Sep 2009 15:51:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help-needed/m-p/4497341#M680718</guid>
      <dc:creator>rhansen</dc:creator>
      <dc:date>2009-09-16T15:51:15Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script help needed</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help-needed/m-p/4497342#M680719</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;One glaring error I see is this line:&lt;BR /&gt;&lt;BR /&gt;filecount=`ls ${directory}/wc -c`&lt;BR /&gt;&lt;BR /&gt;It should be:&lt;BR /&gt;&lt;BR /&gt;filecount=`ls ${directory}|wc -c`&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 16 Sep 2009 15:55:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help-needed/m-p/4497342#M680719</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-09-16T15:55:49Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script help needed</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help-needed/m-p/4497343#M680720</link>
      <description>Hi James,&lt;BR /&gt;&lt;BR /&gt;I did fix that error but still there is no message displayed when there are no files to be uploaded.&lt;BR /&gt;&lt;BR /&gt;Thanks.</description>
      <pubDate>Wed, 16 Sep 2009 16:25:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help-needed/m-p/4497343#M680720</guid>
      <dc:creator>rhansen</dc:creator>
      <dc:date>2009-09-16T16:25:09Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script help needed</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help-needed/m-p/4497344#M680721</link>
      <description>Hi (again):&lt;BR /&gt;&lt;BR /&gt;&amp;gt; I did fix that error but still there is no message displayed when there are no files to be uploaded.&lt;BR /&gt;&lt;BR /&gt;Actually your script won't even run as posted.  You lack closing double quotes on lines 41-and-45 and the 'if/then' on line-20 isn't closed with a matching 'fi'.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 16 Sep 2009 16:34:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help-needed/m-p/4497344#M680721</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-09-16T16:34:57Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script help needed</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help-needed/m-p/4497345#M680722</link>
      <description>Sorry for the missing quotes and the if loop. I have it all covered, it was a mistake in copy n paste. The real issue in my script that I am trying to fix it is to display a message when there are no files to be uploaded else it is working as expected.&lt;BR /&gt;&lt;BR /&gt;Thanks.</description>
      <pubDate>Wed, 16 Sep 2009 18:27:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help-needed/m-p/4497345#M680722</guid>
      <dc:creator>rhansen</dc:creator>
      <dc:date>2009-09-16T18:27:12Z</dc:date>
    </item>
    <item>
      <title>Re: Shell script help needed</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help-needed/m-p/4497346#M680723</link>
      <description>&lt;!--!*#--&gt;Hi (again):&lt;BR /&gt;&lt;BR /&gt;Your problem is that when you 'cd' into an empty directory, an empty list is returned by the statement:&lt;BR /&gt;&lt;BR /&gt;for filename in *&lt;BR /&gt;&lt;BR /&gt;The test for the number of files needs to be moved forward in the code, so that it all looks something like this:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;# set -x&lt;BR /&gt;#&lt;BR /&gt;# Establish and set variables&lt;BR /&gt;host_id="xyz.test.org"&lt;BR /&gt;port_number="\#22"&lt;BR /&gt;user_id="abcd"&lt;BR /&gt;password="password"&lt;BR /&gt;HOME="/home/abcd"&lt;BR /&gt;TMP=${HOME}/tmp&lt;BR /&gt;LOGDIR="/var/adm/ras/"&lt;BR /&gt;&lt;BR /&gt;if [[ $# -ne 1 ]]; then&lt;BR /&gt;    echo "Usage script -u|-d"&lt;BR /&gt;    exit 1&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;if [[ $1 = "-u" ]]; then&lt;BR /&gt;    echo "Upload"&lt;BR /&gt;    while read line&lt;BR /&gt;    do&lt;BR /&gt;        upload_directory=${line}/submission/test&lt;BR /&gt;        directory=${HOME}/upload/test/${line}&lt;BR /&gt;&lt;BR /&gt;        cd ${directory}&lt;BR /&gt;        echo "in directory ${directory}"&lt;BR /&gt;        filecount=`ls ${directory}|wc -c`&lt;BR /&gt;        if [[ ${filecount} -eq 0 ]]; then&lt;BR /&gt;            echo "There is nothing to upload in ${directory}"&lt;BR /&gt;            continue&lt;BR /&gt;        fi&lt;BR /&gt;&lt;BR /&gt;        for filename in *&lt;BR /&gt;        do&lt;BR /&gt;            if [[ -f ${filename} ]]; then&lt;BR /&gt;                filename_abs=${directory}/${filename}&lt;BR /&gt;                    ${HOME}/sftp.exp ${user_id} ${password} ${host_id} ${port_number} ${upload_directory} ${filename}&lt;BR /&gt;                    if [[ $? -eq 0 ]]; then&lt;BR /&gt;                        echo "$(date): ${directory}/${filename} uploaded" ### &amp;gt;&amp;gt; $LOGDIR/sftp_audit.log&lt;BR /&gt;                    else&lt;BR /&gt;                        echo "$(date): ${directory}/${filename} not able to upload" ### &amp;gt;&amp;gt; $LOGDIR/sftp_failure.log&lt;BR /&gt;                    fi&lt;BR /&gt;            fi&lt;BR /&gt;        done&lt;BR /&gt;    done&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;I would also suggest that you re-read my earlier responses in this thread relating to techniques to control loops, but this should solve your essential problem.  Too, if you have hidden files (those filenames beginning with a dot character) then you need to re-read my earlier comments again.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Wed, 16 Sep 2009 20:38:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/shell-script-help-needed/m-p/4497346#M680723</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2009-09-16T20:38:44Z</dc:date>
    </item>
  </channel>
</rss>

