want to delete indexInitializer.log file. so define crontab with this:0 3 * * * rm -rf /alidata1/setupTms3/jboss-eap-6.4/%LOG_DIRECTORY%/tire2e/indexInitializer.log.*
However, all files in the folder /alidata1/setupTms3/jboss-eap-6.4/ were deleted during actual operation.
check cron log found : Jul 21 17:00:01 tmsprod4 CROND[26461]: (root) CMD (rm -rf /alidata1/setupTms3/jboss-eap-6.4/), Why is the suffix(%LOG_DIRECTORY%/tire2e/indexInitializer.log.*) missing during execution. There is no problem with running directly.
You need to backslash the % character, so:
0 3 * * * /bin/rm -rf /alidata1/setupTms3/jboss-eap-6.4/\%LOG_DIRECTORY\%/tire2e/indexInitializer.log
From man 5 crontab:
The 'sixth' field (the rest of the line) specifies the command to be
run. The entire command portion of the line, up to a newline or % character, will be executed by /bin/sh or by the shell specified in the SHELL variable of the crontab file.
Percent signs (%) in the command, unless escaped with backslash (), will be changed into newline characters, and all data after the first % will be sent to the command as standard input. There is no way to split a single command line onto multiple lines, like the shell's trailing "".
Related
I am trying to delete any folder or files in my account inside the cluster using the rm command. But somehow I am not able to do this and getting an error
bash: warning: shell level (1000) too high, resetting to 1
bash: warning: shell level (1000) too high, resetting to 1
/home/.../bin/rm: fork: Cannot allocate memory
The problem is simple yet it might look complex as it shows itself in a rather unexpected way and is caused by not so simple process of command name resolution.
Let me remind you what happens when the shell executes a command like
command_name arg1 ... argn
The shell splits the command line into words separated by spaces and other metacharacters.
It takes the first word and treats at as a command name.
It checks if it contains slashes and if true treats it as a path to a command file and goes to #10
If the check in 3 fails It checks if command name is a name of a built-in command and executes the command if true
If the check in 4 fails it tries to find the command on the file system
It reads the $PATH variable and splits its value into segments separated by columns :.
For each segment it treats it as a path to a directory in the filesystem.
If the directory exists it scans the directory for an executable file name matching the command name if found it appends the command name to the directory name and treats this as a path to the command file and goes to #10
If the file is not found in any of the segments of the $PATH the shell reports an error.
The shell executes the command
command_file arg1 ... argn
Note the difference is that instead of command_name we have got command_file now.
Now what this has to do with your problem.
First your $PATH has /home/.../bin before /bin. So rm myfile becomes /home/.../bin/rm myfile instead of /bin/rm myfile.
Second your /home/.../bin/rm file is a shell script that calls rm $* or something like this. Executing this file results in a non terminating sequence of calls to /home/.../bin/rm myfile.
To check what command is being executed use the command which rm
Option 1
So one option would be to edit /home/.../bin/rm and replace all calls to rm with calls to /bin/rm in the file. Then it would not cause a non terminating sequence of calls.
Option 2
In general it is not a good idea to override standard commands unless you know very well what you are doing, so you could rename /home/.../bin/rm to /home/.../bin/myrm
I tried to schedule crontab for automate kibana dashboard data export, but it's not working.
crontab -e is
* * * * * /home/rehan/Installation/SIEM/ELK%20/Other/test.sh
test.sh file has execution permission but the script is not get run every minute. Any suggestions?
Hi % sign is special character in crontab.Need to escape this with backslash \.
Percent-signs % in the command, unless escaped with backslash \%, will be changed into newline characters, and all data after the first will be sent to the command as standard input. There is no way to split a single command line onto multiple lines, like the shell's trailing \.
I was playing around in my terminal earlier and discovered that I can execute single word commands ('ls','cat','python2.7','exit') by making a file or directory named the same thing as the command. However, I can't execute 'multi-word' commands ('rm\ -rf *','ls -a', 'python2.7\ test.py') (which also led me to discover that you can't remove directories named '-rf' with 'rm -rf *') UNLESS the arguments are in alphabetic order. Seemingly, when you just pass in * to bash it reads the names of the files/directories in alphabetical order, passing each successive name in as an argument to the previous command. Example:
$ mkdir cat
$ touch dog
$ vim dog # at this point I put 'Hello!' into dog
$ *
Hello!
Why does the wildcard character not allow me to execute commands of files with spaces in them but does allow me to execute commands of multiple file names? Thanks!
EDIT: Also aliases don't work for some reason. Example:
$ alias lsa='ls -a'
$ mkdir lsa
$ *
No command 'lsa' found, did you mean:
...
lsa: command not found
Anyone know why this is?
Every command bash processes is subject to several varieties of expansions before bash interprets and acts on the result. The last of those is pathname expansion, wherein bash examines the words of the command (as produced by previous expansions and word splitting) for any that contain any of the unquoted special characters *, ?, and [, and interprets those words as patterns representing file names. After all expansions are performed, any redirections and variable assignments in the expanded command are performed and removed from the command. If any words remain, the first is taken as the name of a command to run. The provenance of that word does not matter.
In pathname expansion, the * matches any string, including the empty string. When bash performs pathname expansion on the word consisting of only *, it expands to the names of all the files in the working directory, except those beginning with a dot (.).
Thus, if your working directory contains just a single file named ls, and you execute the command *, bash expands that command to ls and executes it, producing the output ls. Similarly, if the contents of the directory are echo, Hello,, and World!, then when you execute the command * bash expands it to the equivalent of echo Hello, 'World!', and the command outputs Hello, World!.
That doesn't work as you thought it would for filenames with spaces in them because each file name matching a pattern is expanded to a single word. These are not subsequently split. (Bash does perform "word splitting" as part of the expansion process, but that happens before pathname expansion.) This is normally what you want, for otherwise commands such as rm * would not reliably do what you expect.
That doesn't work with aliases because bash expands aliases when it reads commands, not when it executes them. That has several implications, but one of them is that aliases are interpreted before any expansions are performed. Another is that the replacement text of an alias is subject to all the normal expansions.
I want to ssh to a machine via proxy server and run a script on that server with the inputs as parameters passed
I am using below :
ssh -t tooladm#200.81.36.188 "ssh -t tooladm#apuatt01" ". ./.profile >/dev/null 2>&1; cd /astxpinfs/ast/tooladm/JHF_SYNC_Particular_HF ; ./SyncToSite.ksh $product $release "${hf_list}" ${LOG_DIR_NAME} 2>&1 > /dev/null"
For clearance :
Suppose I am in machine A, and want to run the script located in machine apuatt01
There is no direct connectivity b/w machine A and apuatt01
So I am connecting apuatt01 via 200.81.36.188
By using this, I am not able to run the above script
Please can you help, where I am doing wrong
You can use Bash here document to make the script cleaner:
ssh -t tooladm#200.81.36.188 -- ssh -t tooladm#apuatt01 <<EOS
source .profile >/dev/null 2>&1
cd /astxpinfs/ast/tooladm/JHF_SYNC_Particular_HF
./SyncToSite.ksh $product $release "${hf_list}" ${LOG_DIR_NAME} 2>&1 > /dev/null
EOS
Note, the double dash separates the command from arguments passed to ssh.
This syntax works in ksh, too. From the KornShell manual(man ksh):
<<[-]word The shell input is read up to a line that is the same
as word after any quoting has been removed, or to an end-of-file.
No parameter substitution, command substitution, arithmetic
substitution or file name generation is performed on word. The
resulting document, called a here-document, becomes the standard
input. If any character of word is quoted, then no interpretation is
placed upon the characters of the document; otherwise, parameter
expansion, command substitution, and arithmetic substitution occur,
\new- line is ignored, and \ must be used to quote the characters \,
$, `. If - is appended to <<, then all leading tabs are stripped from
word and from the document. If # is appended to <<, then leading
spaces and tabs will be stripped off the first line of the document
and up to an equivalent indentation will be stripped from the
remaining lines and from word. A tab stop is assumed to occur at
every 8 columns for the purposes of determining the indentation.
I'm trying to understand what is the unix command !$.
For example, I know that the command !1 is used to run the history command number 1.
It seems like !$ runs the last command typed in the bash.
For example if I wrote mv folder12 folder123 and then I would write cd !$ I would actually preform cd folder123.
Is it correct that !$ runs the last command typed in the bash?
!$ matches the last argument of the previous command.
From man bash
yank-last-arg (M-., M-_)
Insert the last argument to the previous command (the last word of
the previous history entry). With an argument, behave exactly
like yank-nth-arg. Successive calls to yank-last-arg move back
through the history list, inserting the last argument of each line in
turn. The history expansion facilities are used to extract the last
argument, as if the "!$" history expansion had been specified.
Example
$ vi a
$ ls -l !$ # expands to "ls -l a"
-rw-rw-r-- 1 me me 30 18 abr. 22:00 a
See also What is your single most favorite command-line trick using Bash?:
I'm a fan of the !$, !^ and !* expandos, returning, from the most
recent submitted command line: the last item, first non-command item,
and all non-command items. To wit (Note that the shell prints out the
command first).
And also a good reading: The Definitive Guide to Bash Command Line History.