Sponsored Content
Top Forums Shell Programming and Scripting Unable to execute find command from inside a shell script Post 303045496 by mohtashims on Saturday 28th of March 2020 04:17:23 AM
Old 03-28-2020
Unable to execute find command from inside a shell script

I have a shell script with 775 permission as below

/app/script/test.sh

Code:
#!/bin/bash
/usr/bin/find /app/Jenkins/home/jobs/test1/builds -type d -mtime 1 |  xargs rm -rf
/usr/bin/find /app/Jenkins/home/jobs/test2/builds -type d -mtime 1 |  xargs rm -rf

When i execute the script it simply runs without the find command getting executed and the files being deleted.

Both the find commands work fine when i execute them manually from the terminal.

I want the script to run both the find commands and perform their respective tasks.

i tried to put backticks `` around the find command but still no luck.

Can you please suggest ?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execute command inside while problem

Hi! How can I execute a linux command inside the while cicle?? like: This doesn't work. Should I replace the by '' or "" (3 Replies)
Discussion started by: ruben.rodrigues
3 Replies

2. Shell Programming and Scripting

deleting files inside shell script - ( using find)

Hi, I am using the command find /apps/qualdb/gpcn/scripts/cab_outbound/archive -name 'z*' -mtime +28 -exec rm {} \; in unix command prompt for deleting the files in my unix system under the specfied folder. It was succesfull. But when i running this command inside a shell script name... (2 Replies)
Discussion started by: Jayaram.Nambura
2 Replies

3. Shell Programming and Scripting

Execute a shell script after a particular command is run

Hi, I need to run a script whenever the Cron file is modified. The requirement is whenever a user modifies the cron file, the script should run automatically. Can you please provide your inputs ? (5 Replies)
Discussion started by: harneet2004us
5 Replies

4. Shell Programming and Scripting

How to monitor a command inside shell script

Hi All, Is there any way to monitor a command inside shell script ? I have a script inside which I have a tar command which zips around 200GB data. tar zcvf $Bckp_Dir/$Box-BaseBackup-$Day.tar.gz * --exclude 'dbserver_logs/*' --exclude postmaster.pid --exclude 'pg_xlog/*' I want to... (3 Replies)
Discussion started by: sussus2326
3 Replies

5. UNIX for Dummies Questions & Answers

Unable to execute the complete cmd - using find command

Hi, I'm unable to execute the below command completely ; it's not allowing me to type the complete command. It is allowing till "xargs" and i cannot even press enter after that. I'm using Solaris. Let me know if anything needs to be added so as to execute the complete command. Appreciate... (12 Replies)
Discussion started by: venkatesht
12 Replies

6. Shell Programming and Scripting

When i am trying to execute export command within a shell script it is saying command not found.

I am running the export command within a view to use that value inside my build script. But while executing it it is saying "export command not found" My code is as follows: -------------------------- #!/bin/sh user="test" DIR="/bldtmp/"$user VIEW="test.view1" echo "TMPDIR before export... (4 Replies)
Discussion started by: dchoudhury
4 Replies

7. Shell Programming and Scripting

Can i use if else inside expect command in shell script?

hii,, I am trying to automate jira. during my scripting using bash script, in the terminal i got the terminal message like this: "Configure which ports JIRA will use. JIRA requires two TCP ports that are not being used by any other applications on this machine. The HTTP port is where you... (1 Reply)
Discussion started by: nithinfluent
1 Replies

8. Shell Programming and Scripting

How to find whether a particular command has failed inside an sftp script?

hi, how can i know whether a command inside an sftp script has failed or not? i have a sftp expect script #!/usr/bin/expect spawn /usr/bin/sftp abc@ftp.abc.com expect "sftp>" send "cd dir\r" expect "sftp>" send "mput abc.txt\r" expect "sftp>" send "mput def.xls\r" expect "sftp>"... (5 Replies)
Discussion started by: Little
5 Replies

9. Shell Programming and Scripting

How to execute a command inside a while loop?

How do we execute a command inside a while loop? (7 Replies)
Discussion started by: Little
7 Replies

10. Shell Programming and Scripting

Unable to pass shell script variable to awk command in same shell script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk... (2 Replies)
Discussion started by: Ashunayak
2 Replies
xjobs(1)							   User Commands							  xjobs(1)

NAME
xjobs - construct command line and execute jobs in parallel SYNOPSIS
xjobs [options] [utility [argument ...]] DESCRIPTION
xjobs reads job descriptions line by line and executes them in parallel. It limits the number of parallel executing jobs and starts new jobs when jobs finish. Therefore, it combines the arguments from every input line with the utility and arguments given on the command line. If no utility is given as an argument to xjobs, then the first argument on every job line will be used as utility. To execute utility xjobs searches the directories given in the PATH environment variable and uses the first file found in these directories. xjobs is most useful on multiprocessor machines when one needs to execute several time consuming commands that could possibly be run in parallel. With xjobs this can be achieved easily, and it is possible to limit the load of the machine to a useful value. It works similar to xargs, but starts several processes simultaneously and gives only one line of arguments to each utility call. By using I/O redirectors the standard input, output, and error stream of executed jobs can be redirected. Use < to redirect standard input, > to redirect standard output, >! to redirect standard output and overwrite an existing file, >> to append standard output to an existing file, >& to redirect both standard output and standard error output to the same file, and >>& to append both standard output and standard error output to the same file. If passed on the command line, these operators specify the default I/O redirection that can be overwritten by specifying another redirector to a specific job on its argument line. After all these operators a filename is expected. See EXAMPLES below for an example. If you need more advanced shell features than the redirection operators supported by xjobs, then use as utility a shell of your preference. Every job line can be preceeded by a "cd directory;" command that tells xjobs in which directory the job shall be executed. For every line this can only be used once. For more complex scripting, please pass the line to execute to a shell of your choice. xjobs constructs the arguments of the jobs to execute from each input line. Each input line will create a seperate job, whereas newline character are handled as regular whitespace by xargs. To be able to include whitespace charakters in arguments, either preceed them with a backslash or quote them with single or doublequote charakters. A backslash charakter preceeding a newline will make xjobs ignore the new- line character, thus giving you the ability to pass arguments for a single job across multiple lines. To include quotation marks in quoted arguments, preceed them with a backslash. Lines passed to xjobs beginning with a # charakter are interpreted as comments. Finally, xjobs also includes a mechanism for serializing the execution. Like this it is possible to parallelize independent jobs and sequence jobs that have a dependency. This can be achieved by inserting a line that only consists of two percentage charakters in sequence (%%). All jobs before this sequence point are executed at the requested number of jobs in parallel. When hitting the sequence point xjobs waits for all processes to finish and then continues starting jobs that follow the sequence point. When passing a named pipe (i.e. a file name created by mkfifo) via option -s as an input, xjobs will close and reopen the fifo when reach- ing end-of-file. Like this it is possible to setup an xjobs server and sending jobs to this server from muliple programs. See section EXAM- PLES below for an example. OPTIONS
-j <jobs> Sets the maximum number of jobs that are started in parallel. The default value is to limit the number executing jobs is equal to the number of online processors in the system. If the number passed as <jobs> is followed by an 'x' charakter (e.g. 2.5x), the value is multiplied with the number of online processors before setting the job limit. I.e. having a machine with 4 online processors and passing 2.5x as an argument to option -j will yield a joblimit of 10 jobs. -s <script> Use file script instead of the standard input to read the job descriptions. -n Redirect standard output and standard error output of executed jobs to /dev/null. -l <num> Combine the arguments of <num> input lines for a single job. -p Start jobs interactively, prompting the user. -q <num> Limits the number of queued jobs to num elements. Normally xjobs reads in jobs from standard input or the give script and queues them if they cannot be started at once. With this option, xjobs will stop reading as soon as num jobs are queued and restart reading when a new job has been started. Like this xjobs allocates less memory. Use this option, if you pass huge number of jobs to xjobs, to limit memory consumption. It can also increase performance of xjobs, but be sure that jobs get fed fast enough to xjobs. -1 Pass one argument per job, which is expected to be terminated by a new-line character. No argument parsing is performed. That way it is more easy to process jobs where arguments may include whitespace character or other tokens that influence argument parsing. -0 Same as -1, but as a job and argument termination character a null-character () is expected instead of a new-line character. That way also arguments with new-line character can be processed without escape sequences. -V Print the version number of xjobs and exit. -v <level> Set verbosity of xjobs to level. Valid leves are: 0=silent, 1=error, 2=warning, 3=info, 4=debug. The default level of verbosity is 3. EXAMPLES
If you have a lot of .zip files that you want to extract, then use xjobs like this: $ ls -1 *.zip | xjobs unzip If you want to do the same without getting the output of each unzip task on your terminal, then try this: $ ls -1 *.zip | xjobs -n unzip To gzip all *.bak files in a given directory hierarchy, use it the following way: $ find . -name '*.bak' | xjobs gzip To generate index files for a set of *.jar files, you can use the redirection feature of xjobs, and do the following: $ ls -1 *.jar | sed 's/(.*)/1 > 1.idx/' | xjobs jar tf If you also want to capture the error output, than use >& instead of >. You can also use it to execute several different commands. Therefore, write a script file that contains every job you want to execute and pass it to xjobs with the option -s: $ cat - > script unzip my.zip tar xf my.tar lame --silent my.wav my.mp3 crypt notsecret < mydata > secretfile ^D $ xjobs -s script To be able to queue up jobs from multiple sources with xjobs, use a named pipe and pass it explicitly as input script. Then write the jobs to the named pipe: $ mkfifo /var/run/my_named_pipe $ xjobs -s /var/run/my_named_pipe & $ echo unzip 1.zip >> /var/run/my_named_pipe $ echo tar cf /backup/myhome.tar /home/me >> /var/run/my_named_pipe ENVIRONMENT VARIABLES
PATH Determines the location of command. AUTHORS
Thomas Maier-Komor <thomas@maier-komor.de> Donations via PayPal are welcome! HOMEPAGE
http://www.maier-komor.de/xjobs.html LICENSE
GNU General Public License Version 2 SEE ALSO
xargs(1) Thomas Maier-Komor 20100915 xjobs(1)
All times are GMT -4. The time now is 05:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy