Bookmarks

Yahoo Gmail Google Facebook Delicious Twitter Reddit Stumpleupon Myspace Digg

Search queries

Wwwwxxx reemine, WWWXXX.VCBA, WWWXXX.VCBA, TheboL.wwwxxxxx, WWWXXXAPC , wwwxxn.xsss, wwwxxxapc, WWWXXX.VCBA, wwwxxx vba, wwwxxxdoco

Links

XODOX
Impressum

#1: Convert Bash shell script to Korn shell script

Posted on 2004-11-23 01:42:34 by jrefactors

The following bash script works fine to delete all files that are
older than $1 minutes. To execute this script,
bash cleanup +10

find /mypath -type f -cmin $1 -exec rm -f {} \;

Unfortunately, now I just realize I need to make it work in Korn
Shell. Even I
change the header from #!/bin/bash to #!/usr/bin/ksh, and execute the
script by ksh cleanup +10, it still have
different errors:

cleanup[9]: -cmin: not found.
cleanup[10]: -type: not found.


Looks like it doesn't work anymore. I think I need to re-write the
Korn Shell script that do the task.
I tried to search for equivalent Korn shell commands but unsuccessful.


Please help. thanks!!

Report this message

#2: Re: Convert Bash shell script to Korn shell script

Posted on 2004-11-23 03:12:50 by William Park

Matt <jrefactors@hotmail.com> wrote:
> The following bash script works fine to delete all files that are
> older than $1 minutes. To execute this script,
> bash cleanup +10
>
> find /mypath -type f -cmin $1 -exec rm -f {} \;
>
> Unfortunately, now I just realize I need to make it work in Korn
> Shell. Even I
> change the header from #!/bin/bash to #!/usr/bin/ksh, and execute the
> script by ksh cleanup +10, it still have
> different errors:
>
> cleanup[9]: -cmin: not found.
> cleanup[10]: -type: not found.
>
>
> Looks like it doesn't work anymore. I think I need to re-write the
> Korn Shell script that do the task.
> I tried to search for equivalent Korn shell commands but unsuccessful.
>
>
> Please help. thanks!!

Try typing it out on your command-line. I don't think this is Bash/Ksh
issue.

--
William Park <opengeometry@yahoo.ca>
Linux solution for data management and processing.

Report this message

#3: Re: Convert Bash shell script to Korn shell script

Posted on 2004-11-23 14:27:24 by sharma__r

jrefactors@hotmail.com (Matt) wrote in message news:

>
> The following bash script works fine to delete all files that are
> older than $1 minutes. To execute this script,
> bash cleanup +10
>
> find /mypath -type f -cmin $1 -exec rm -f {} \;
>
> Unfortunately, now I just realize I need to make it work in Korn
> Shell. Even I
> change the header from #!/bin/bash to #!/usr/bin/ksh, and execute the
> script by ksh cleanup +10, it still have
> different errors:
>
> cleanup[9]: -cmin: not found.
> cleanup[10]: -type: not found.
>
>
> Looks like it doesn't work anymore. I think I need to re-write the
> Korn Shell script that do the task.
>

change 'find' to '/bin/find'.

probably your ksh has 'find' aliased.

Report this message

#4: Re: Convert Bash shell script to Korn shell script

Posted on 2004-11-23 18:46:09 by jrefactors

> change 'find' to '/bin/find'. probably your ksh has 'find' aliased.

I tried it, it still doesn't work. Let me make the descriptions more
clear.

Here's the bash script that worked in home's Linux before, and then I
put this script
to Unix, and no longer works with error "ksh: bash: not found." I
guess the
Unix environment setting doesn't support bash scripts?

#!/bin/bash
find /usr/local/opt/WebSphere/AppServer/installedApps/proj1App.ea r/proj1.war/proj1/download
-type f -cmin $1 -exec rm -f {} \;

$ bash cleanup +5
ksh: bash: not found


I then replaced the header with #!/usr/bin/ksh, and it has another
error "-cmin is not a valid option."
#!/usr/bin/ksh
find /usr/local/opt/WebSphere/AppServer/installedApps/proj1App.ea r/proj1.war/proj1/download
-type f -cmin $1 -exec rm -f {} \;

$ ksh cleanup +5
find: 0652-017 -cmin is not a valid option.


I don't want to change any setting in unix, but I have no idea what to
do now. I guess I
need to re-write the bash shell script to korn shell script?


Thanks again. Please advise.

Report this message

#5: Re: Convert Bash shell script to Korn shell script

Posted on 2004-11-23 19:04:42 by Stephane CHAZELAS

2004-11-23, 09:46(-08), Matt:
[...]
> I then replaced the header with #!/usr/bin/ksh, and it has another
> error "-cmin is not a valid option."
> #!/usr/bin/ksh
> find /usr/local/opt/WebSphere/AppServer/installedApps/proj1App.ea r/proj1.war/proj1/download
> -type f -cmin $1 -exec rm -f {} \;
>
> $ ksh cleanup +5
> find: 0652-017 -cmin is not a valid option.
[...]

-cmin is a GNU (and BSD) specific option. There's no equivalent
option in standard find.

Note that -cmin is for the inode last change time, I doubt this
is what you want.

If you want to remove the files that have not been modified
withing the last $1 minutes, then you can use perl:

#! /usr/bin/perl
use File::Find;
$minutes = $ARGV[0];
find sub { unlink if (-M) * 24 * 60 > $minutes },
"/usr/local/opt/WebSphere/AppServer/installedApps/proj1App.e ar/proj1.war/proj1/download"

(untested)

--
Stephane

Report this message

#6: Re: Convert Bash shell script to Korn shell script

Posted on 2004-11-23 19:14:32 by William

"Matt" <jrefactors@hotmail.com> wrote in message
news:ba8a039e.0411230946.1a2ae394@posting.google.com...
>
> I then replaced the header with #!/usr/bin/ksh, and it has another
> error "-cmin is not a valid option."
> #!/usr/bin/ksh
> find
/usr/local/opt/WebSphere/AppServer/installedApps/proj1App.ea r/proj1.war/proj
1/download
> -type f -cmin $1 -exec rm -f {} \;

It isn't a valid option for the find on my machine, the only option it
supports is -ctime, which would do what you want. -Wm

Report this message

#7: Re: Convert Bash shell script to Korn shell script

Posted on 2004-11-23 19:30:15 by Ed Morton

Matt wrote:
>>change 'find' to '/bin/find'. probably your ksh has 'find' aliased.
>
>
> I tried it, it still doesn't work. Let me make the descriptions more
> clear.
>
> Here's the bash script that worked in home's Linux before, and then I
> put this script
> to Unix, and no longer works with error "ksh: bash: not found." I
> guess the
> Unix environment setting doesn't support bash scripts?

Not necessarily, it just apparently isn't in "/bin" on your system. It
MAY be in "/usr/bin" (or elsewhere) in which case your shebang should be
"#!/usr/bin/bash" instead of "#!/bin/bash". That wouldn't solve your
main problem though. Your main problem has nothing whatsoever to do with
whether you're using a bash or ksh shell, it's which version of "find"
you're using as discussed elsethread.

<snip>

> I don't want to change any setting in unix, but I have no idea what to
> do now. I guess I
> need to re-write the bash shell script to korn shell script?

No, you need to download and install GNU "find".

Ed.

Report this message

#8: Re: Convert Bash shell script to Korn shell script

Posted on 2004-11-23 20:39:16 by dfrench

Matt wrote:
> The following bash script works fine to delete all files that are
> older than $1 minutes. To execute this script,
> bash cleanup +10
>
> find /mypath -type f -cmin $1 -exec rm -f {} \;
>
> Unfortunately, now I just realize I need to make it work in Korn
> Shell. Even I
> change the header from #!/bin/bash to #!/usr/bin/ksh, and execute the
> script by ksh cleanup +10, it still have
> different errors:
>
> cleanup[9]: -cmin: not found.
> cleanup[10]: -type: not found.
>
>
> Looks like it doesn't work anymore. I think I need to re-write the
> Korn Shell script that do the task.
> I tried to search for equivalent Korn shell commands but
unsuccessful.
>

Do the following:
1. Start a bash shell: "bash"
2. run the command "which find"
3. exit the bash shell: "exit"
4. start a ksh: "ksh"
5. run the command "which find"
6. exit the ksh
7. use the find command identified in the bash shell as
the path to the find command in the ksh script. The
path will probably be "/usr/local/bin/find"

--
Dana French

Report this message

#9: Re: Convert Bash shell script to Korn shell script

Posted on 2004-11-24 11:12:11 by Bill Marcum

On Tue, 23 Nov 2004 12:14:32 -0600, William
<Reply@NewsGroup.Please> wrote:
> "Matt" <jrefactors@hotmail.com> wrote in message
> news:ba8a039e.0411230946.1a2ae394@posting.google.com...
>>
>> I then replaced the header with #!/usr/bin/ksh, and it has another
>> error "-cmin is not a valid option."
>> #!/usr/bin/ksh
>> find
> /usr/local/opt/WebSphere/AppServer/installedApps/proj1App.ea r/proj1.war/proj
> 1/download
>> -type f -cmin $1 -exec rm -f {} \;
>
> It isn't a valid option for the find on my machine, the only option it
> supports is -ctime, which would do what you want. -Wm
>
-[cma]time searches for files according to the age in days, whereas
-[cma]min uses minutes. When the "min" options aren't available, you
can use touch and "find -newer" or "find ! -newer"


--
"At a scheduled time, the robot would pull the flush lever and scream as
it got sucked down the drain." --Kibo

Report this message

#10: Re: Convert Bash shell script to Korn shell script

Posted on 2004-11-24 16:45:54 by Dan Mercer

When I see problems like this I want to go back to first principles.
What are you really trying to do. I will assume for now that you
want to run a script, either from batch or cron, to clean up a
temp directory. Let's assume every ten minutes you run the following
script as root to clean up /usr/tmp of files beginning with sh:

#!/usr/bin/ksh
VARDIR==/var/${0##*/}
TOUCHSTONE=$VARDIR/touchstone
[[ -d $VARDIR ]] || mkdir $VARDIR ||
{
print -u2 "Fatal error - can't make $VARDIR"
exit 1
}

trap '>$TOUCHSTONE' exit

cd /usr/tmp

for file in sh*
do
[[ -f $file ]] || continue
[[ $file -ot $TOUCHSTONE ]] || continue
rm -f $TOUCHSTONE
done


This is portable to all ksh versions and does not require any
external command other than rm

Dan Mercer

Report this message