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
App::Cmd::Tutorial(3pm) 				User Contributed Perl Documentation				   App::Cmd::Tutorial(3pm)

NAME
App::Cmd::Tutorial - getting started with App::Cmd VERSION
version 0.318 DESCRIPTION
App::Cmd is a set of tools designed to make it simple to write sophisticated command line programs. It handles commands with multiple subcommands, generates usage text, validates options, and lets you write your program as easy-to-test classes. An App::Cmd-based application is made up of three main parts: the script, the application class, and the command classes. The script is the actual executable file run at the command line. It can generally consist of just a few lines: #!/usr/bin/perl use YourApp; YourApp->run; All the work of argument parsing, validation, and dispatch is taken care of by your application class. The application class can also be pretty simple, and might look like this: package YourApp; use App::Cmd::Setup -app; 1; When a new application instance is created, it loads all of the command classes it can find, looking for modules under the Command namespace under its own name. In the above snippet, for example, YourApp will look for any module with a name starting with "YourApp::Command::". We can set up a simple command class like this: package YourApp::Command::initialize; use YourApp -command; 1; Now, a user can run this command, but he'll get an error: $ yourcmd initialize YourApp::Command::initialize does not implement mandatory method 'execute' Oops! This dies because we haven't told the command class what it should do when executed. This is easy, we just add some code: sub execute { my ($self, $opt, $args) = @_; print "Everything has been initialized. (Not really.) "; } Now it works: $ yourcmd initialize Everything has been initialized. (Not really.) The arguments to the execute method are the parsed options from the command line (that is, the switches) and the remaining arguments. With a properly configured command class, the following invocation: $ yourcmd reset -zB --new-seed xyzxy foo.db bar.db might result in the following data: $opt = { zero => 1, no_backup => 1, new_seed => 'xyzzy', }; $args = [ qw(foo.db bar.db) ]; Arguments are processed by Getopt::Long::Descriptive (GLD). To customize its argument processing, a command class can implement a few methods: "usage_desc" provides the usage format string; "opt_spec" provides the option specification list; "validate_args" is run after Getopt::Long::Descriptive, and is meant to validate the $args, which GLD ignores. The first two methods provide configuration passed to GLD's "describe_options" routine. To improve our command class, we might add the following code: sub usage_desc { "yourcmd %o [dbfile ...]" } sub opt_spec { return ( [ "skip-refs|R", "skip reference checks during init", ], [ "values|v=s@", "starting values", { default => [ 0, 1, 3 ] } ], ); } sub validate_args { my ($self, $opt, $args) = @_; # we need at least one argument beyond the options; die with that message # and the complete "usage" text describing switches, etc $self->usage_error("too few arguments") unless @$args; } TIPS
o Delay using large modules using autouse, Class::Autouse or "require" in your commands to save memory and make startup faster. Since only one of these commands will be run anyway, there's no need to preload the requirements for all of them. o To add a "--help" option to all your commands create a base class like: package MyApp::Command; use App::Cmd::Setup -command; sub opt_spec { my ( $class, $app ) = @_; return ( [ 'help' => "This usage screen" ], $class->options($app), ) } sub validate_args { my ( $self, $opt, $args ) = @_; if ( $opt->{help} ) { my ($command) = $self->command_names; $self->app->execute_command( $self->app->prepare_command("help", $command) ); exit; } $self->validate( $opt, $args ); } Where "options" and "validate" are "inner" methods which your command subclasses implement to provide command-specific options and validation. o Add a "description" method to your commands for more verbose output from the built-in "App::Cmd::Command::help|help" command. sub description { return "The initialize command prepares ..."; } o To let your users configure default values for options, put a sub like sub config { my $app = shift; $app->{config} ||= TheLovelyConfigModule->load_config_file(); } in your main app file, and then do something like: sub opt_spec { my ( $class, $app ) = @_; my ( $name ) = $class->command_names; return ( [ 'blort=s' => "That special option", { default => $app->config->{$name}{blort} || $fallback_default }, ], ); } Or better yet, put this logic in a superclass and process the return value from an "inner" method (see previous tip for an example). AUTHOR
Ricardo Signes <rjbs@cpan.org> COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Ricardo Signes. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.14.2 2012-05-05 App::Cmd::Tutorial(3pm)
All times are GMT -4. The time now is 03:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy