Solved

execute script and delete himself after success

Posted on 2006-07-08
10
297 Views
Last Modified: 2013-12-16
i want to exexute a schript from a folder and then delete this a take the next entry from the folder.

i have a folder with a lot of script creted by '' split -l10  fillist" command.
so i have a lot file with names are starting with xaa and goes x**
all files are executeable.
if have a jobvariable $my_jobs.

if $my_jobs=0 then
'call the first file in my exec-folder
if
0
Comment
Question by:ebertsys
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 22

Expert Comment

by:pjedmond
ID: 17064323
'call the first file in my exec-folder only
---------------------------------------------------------X8--------------
MYDIR=/home/me/scripts

MYFILE in `ls | grep -e ^x | grep -e ^x`
exec ${MYFILE}
rm -Rf ${MYFILE}
---------------------------------------------------------X8--------------


...or 'call the files starting with an x file in my exec-folder:
---------------------------------------------------------X8--------------
MYDIR=/home/me/scripts
cd $MYDIR

        for MYFILE in `ls | grep -e ^x` ; do
            exec ${MYFILE}
            rm -Rf ${MYFILE}
        done

---------------------------------------------------------X8--------------
(   (()
(`-' _\
 ''  ''



0
 
LVL 22

Expert Comment

by:pjedmond
ID: 17064329
Ooops - need to change into the correct directory first!

'call the first file in my exec-folder only
---------------------------------------------------------X8--------------
MYDIR=/home/me/scripts
cd $MYDIR
MYFILE in `ls | grep -e ^x | grep -e ^x`
exec ${MYFILE}
rm -Rf ${MYFILE}
---------------------------------------------------------X8--------------
(   (()
(`-' _\
 ''  ''
0
 

Author Comment

by:ebertsys
ID: 17064410
sorry i'm a linux newbie..:)

myjobs=`gdsjob -l |grep -c 0                             # give a count of jobrows..
 for MYFILE in `ls | grep -e ^x` ; do
if $myjobs=0 ;then                                            #when no jobs there run script
            exec ${MYFILE}
            rm -Rf ${MYFILE}
if
        done


when i use it in this way i get an syntax error unexpeted token if   ??


0
Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

 

Author Comment

by:ebertsys
ID: 17064427
it's wrong..
what i want...
if the joblist is 0 then

the first file should be executet
and then delete

else
exit script.

end if

the mainscript i will call with an watch -n60
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 17064518
In which case:

insert this one into your script (sorry messed up the cut and paste last time:

'call the first file in my exec-folder only, and then delete it
---------------------------------------------------------X8--------------
MYDIR=/home/me/scripts
cd $MYDIR
MYFILE in `ls | grep -e ^x | sed -e q`      #Note the sed command rather than the grep - this takes the first file only
exec ${MYFILE}
rm -Rf ${MYFILE}
---------------------------------------------------------X8--------------
(   (()
(`-' _\
 ''  ''
0
 
LVL 22

Expert Comment

by:pjedmond
ID: 17064527
Comments and insertions on your script:

----8X-----------
MYDIR=/home/me/scripts                                   #Need to change into the correct scripts directory for                
cd $MYDIR                                                         #the ls to work correctly.
myjobs=`gdsjob -l |grep -c 0                             # give a count of jobrows..
 for MYFILE in `ls | grep -e ^x | sed -e q` ; do                   #added sed -e q to take the first only
if $myjobs=0 ;then                                            #when no jobs there run script
            exec ${MYFILE}
            rm -Rf ${MYFILE}
end if              #<---------------------------------------------- end if perhaps;)..hence unexpected token!
        done
----8X-----------

(   (()
(`-' _\
 ''  ''
0
 
LVL 22

Accepted Solution

by:
pjedmond earned 200 total points
ID: 17064538
Try again - You've got a number of inconsistencies using 'different shells', combined with a few syntax errors from me;) Therefore I will use Bash:

Comments and insertions on your script:

----8X-----------
#!/bin/bash
MYDIR=/home/me/scripts                                   #Need to change into the correct scripts directory for                
cd $MYDIR                                                         #the ls to work correctly.
myjobs=`gdsjob -l |grep -c 0`                           # give a count of jobrows..
MYFILE = `ls | grep -e ^x | sed -e q` ; do                   #added sed -e q to take the first only
if  [ "$myjobs" = "0" ]; then                                            #when no jobs there run script
            exec ${MYFILE}
            rm -Rf ${MYFILE}
fi              #<---------------------------------------------- fi perhaps;)..hence unexpected token!
                                                                               #if else fi for bash
----8X-----------

http://www.faqs.org/docs/Linux-HOWTO/Bash-Prog-Intro-HOWTO.html#ss6.3

for the structure of conditionals in bash.

(   (()
(`-' _\
 ''  ''
0
 

Author Comment

by:ebertsys
ID: 17064598
i forgott the do in the if line and know i take the if row in remarks and it look as it should
i get an xab back what is the first script in the DIR.
but on exec ${myfile}             #the { and not (
i get an 'line 8 exec:xab:not found
mybe permissions?
----8X-----------
#!/bin/bash
myjobs=`gdsjob -l |grep -c 0`                             # give a count of jobrows..
 for MYFILE in `ls | grep -e ^x | sed -e q` ; do                   #added sed -e q to take the first only-----it's okay
#if $myjobs=0 ;then                                            #when no jobs there run script
            exec ${MYFILE}
            rm -Rf ${MYFILE}
#fi
done
----8X-----------

0
 

Author Comment

by:ebertsys
ID: 17064603
no it was the complite path
0
 

Author Comment

by:ebertsys
ID: 17064606
please ...at last ...what is wrong with my if...then...else....you know i'm old(50) stupid windows user:)
0

Featured Post

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question