|
Search Forums:
|
|||||||
| Forums | Register | Forum Rules | Linux and Unix Links | Man Pages | Albums | FAQ | Users | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Count number of files and use result as variable
Hi there I have a .ksh script that I am using on an AIX ( Actual Level 5.3.10.0, Maintenance Level 5.3.0.0) where I am logging into a windows box, doing a file count on that server and returning the output to the UNIX session. I would like to exit the script at this point in time if the value is greater than 1. I have attempted to write this function into the script, but the variable that I am setting is not being echoed out as required. When I run the script below, the result is Quote:
Code:
#!/usr/bin/ksh
numfiles=$(ssh <SERVER> cmd /c 'dir/b/a-d <PATH> | find /c ".CSV"')
print $numfiles
if [ $numfiles -gt 0 ]
then
echo "There are "$numfiles" in the <PATH> directory. Transfer has been stopped."
fiCan anyone assist with a solution to this issue? Any help would be greatly appreciated |
| Sponsored Links | |
|
|
|
#2
|
||||
|
||||
|
what is the output of print statement ? Code:
print $numfiles |
| Sponsored Links | ||
|
|
|
#3
|
|||
|
|||
|
It prints out the correct value, in this case 1 (I have verified that there is only 1 file in the directory!)
|
|
#4
|
||||
|
||||
|
In your statement, you mentioned "I would like to exit the script at this point in time if the value is greater than 1" But you are checking for > 0 in condition replace your if condition as below and let me know the output Code:
if [ $numfiles -gt 0 ]
then
echo "$numfiles"
echo "There are "$numfiles" in the <PATH> directory. Transfer has been stopped."
else
echo "$numfiles"
fi |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
Quote:
Quote:
|
| Sponsored Links | |
|
|
#6
|
||||
|
||||
|
replace the echo statement. seems, your $numfiles is holding the value of 1 Code:
echo "There are $numfiles in the <PATH> directory. Transfer has been stopped." |
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
I had tried that before itkamaral, but it returns the same results:
Quote:
|
| Sponsored Links | ||
|
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Count number of files in directory excluding existing files | ammu | UNIX for Dummies Questions & Answers | 3 | 08-25-2010 01:54 PM |
| Count the number of files without ls | spkandy | Shell Programming and Scripting | 37 | 07-01-2010 09:41 AM |
| count number of files in a directory | finalight | Shell Programming and Scripting | 5 | 05-14-2009 07:57 AM |
| Count the number of files in a directory | Raynon | Shell Programming and Scripting | 14 | 08-16-2007 10:07 PM |
| Count number of files in subdirectories | cbeverly | UNIX for Dummies Questions & Answers | 2 | 06-02-2005 03:06 PM |
|
|