Solved

execute script and delete himself after success

Posted on 2006-07-08
10
293 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
  • 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

733 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