Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Shell Script behaviour and syntax Post 303045796 by Cybora on Monday 13th of April 2020 03:45:46 PM
Old 04-13-2020
Shell Script behaviour and syntax

Here are the 3 scripts(FirstScrpt.sh,firstcallScrpt.sh,startProcess.sh) that were running in the server for the past several years.
I understand the way it is written is that for every 1 hour 'firstcallScript.sh' is being called in that it kills the pid of 'startProcess.sh'
and starts again.

2 things I noticed
1. Value of pid.txt never changes if it is being is killed and created every hour.
2. It never runs in the background even when it is run with '&' like (./FirstScrpt.sh &)

FirstScrpt.sh
Code:
#!/bin/bash

if [ $# -ne 1 ]
then
	echo "Usage:  $0 test|prod"
	exit 1
fi
envRun=$1

  echo "Level is :  ${envRun}"
	while [ 1 ]
	do
	cat pid.txt | xargs -l1 kill
	./firstcallScript.sh ${envRun}
	sleep 3600
	done

firstCallScript.sh
Code:
#!/bin/bash

if [ $# -ne 1 ]
then
	echo "Usage:  $0 test|prod"
	exit 1
fi
envRun=$1

if [ $envRun = "test" ] 
then
  echo "Level is  :  ${envRun}"
     ./startProcess.sh ${envRun}
   
 else
   echo "Level is test Invoke test script :  ${envRun}"
   	./startProcess.sh ${envRun}
	
fi

startProcess.sh

Code:
#!/bin/bash 
envRun=$1
echo "${envRun}"
echo "I'm a Linux user."
echo $! > pid.txt


Last edited by Cybora; 04-13-2020 at 04:53 PM.. Reason: Edited the firstScript for 1 hour of sleep
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

any explanation for thsi shell script behaviour

hello whats the difference between excuting a shell script as a)sh myscript.sh b). ./myscript.sh i noticed that my shell script works fine when i run it as . ./myscript .sh but fails when i run it as sh myscript.sh could anybody explain why. the shell script is very simple ... (9 Replies)
Discussion started by: xiamin
9 Replies

2. Shell Programming and Scripting

Shell script syntax checker

I have a rather big script that i have written in ksh and it is falling over in two places with a 'test argument' error. I know this usually means that the if statement is not correct, but it is fine. I have looked through the rest of the script for any odd brackets or ` marks, but can't see... (2 Replies)
Discussion started by: handak9
2 Replies

3. Shell Programming and Scripting

Basic Shell script syntax help

Hi All, I am new to shell scripting. I have a variable which holds a numeric value.I have to check whether this variable holds a value between(0- 8),(8-17)(17-24).How do i write this syntax using if in shell scripting. Thanks Vignesh (2 Replies)
Discussion started by: vignesh53
2 Replies

4. Shell Programming and Scripting

How to Check Shell script syntax w/o executing

Hello All, I looking for a way to verify the correction of shell script syntax. Is there any switch like -c in perl which do this in shell ? Thank You. (1 Reply)
Discussion started by: Alalush
1 Replies

5. Shell Programming and Scripting

Help Syntax Shell-Script

Hi Guys, iīve a question ... but itīs a litte bit tricky: iīve a 3 php-scripts which runīs via cron at night. These script reads an xml-file a writes it in an MySQL-DB. I named them (for example here ) Script1 - Script3. The XML-Files i named xml1 - xml3. Now, iīve build a Batch-file,... (10 Replies)
Discussion started by: jackcracker
10 Replies

6. Shell Programming and Scripting

Syntax error calling TCL script from shell script

hello everyone i am beginner on shell scripting .and i am working on my project work on ad hoc network i wrote a batch (.sh) to do a looping and execute a tcl script i wrote before in each iteration ..but i got this problem " syntax error near unexpected token `('... (1 Reply)
Discussion started by: marcoss90
1 Replies

7. Shell Programming and Scripting

shell script | bc syntax format

sorry but need help http://i.investopedia.com/inv/articles/site/CalculationEMA.gif trying to achieve ema in script I have this syntax which errors ema=` ; the 0.153846154 ='s Smoothing Factor really appreciate help (3 Replies)
Discussion started by: harte
3 Replies

8. Shell Programming and Scripting

syntax error in shell script

I am creating a shell script. In which, I need to get server name and server IP. I used this command in script. servername=`cat /etc/hosts|grep `eval hostname`|awk '{print $2}'` however, when execute script or put set -x to debug, it return: line 13: syntax error at line 13: `|' unexpected... (4 Replies)
Discussion started by: duke0001
4 Replies

9. Shell Programming and Scripting

Bash syntax behaviour : [[ vs [

Hello. In the following : RESTORE_FF contain a file name : a_file.tar.gz I am testing in a directory if "a_file.tar.gz" exists and or if any file like "a_file.tar.gz" exists. So "a_file.tar.gz" will give me file exists So "a_file.tar.gz." will give me file exists So... (5 Replies)
Discussion started by: jcdole
5 Replies

10. Shell Programming and Scripting

Help with if statement syntax in shell script

I want to make the file test condition a variable ($Prmshn in code below). My goal is to use something like the first three unsuccessful if statetments since the 'if #!/bin/ksh test_input() { Prmshn=${1} InFLNm=${2} ifReq="-$Prmshn $InFLNm" #the following three if statments fail: #if ] ;... (10 Replies)
Discussion started by: ms63707
10 Replies
hexec(1)																  hexec(1)

NAME
hexec - a process execution hooking tool SYNOPSIS
hexec <OPTIONS> [expr] [cmd] [args...] DESCRIPTION
hexec is a tool to hook into process exececution calls (exec family of syscalls). You can define an expression that is executed against any hooked exec call. This expression may also contain a replacement exec call. OPTIONS SUMMARY
Here is a summary of the options to hexec. --help | -h Print a options/expr summary page --version | -v Print hexec version --log-out | -lo set output file for error and -print output OPTIONS
-h Print a options/expr summary page --help Print a options/expr summary page -lo Set the output file for error and -print output. This can be required if writing to stderr could cause malfunction because some processes read from stderr and expect a well defined output. EXPRESSIONS
The expression is executed against all process execution calls. If the expression returns true, the original call is skipped. <expr> -and <expr> <expr> -a <expr> <expr> <expr> Returns true if both expressions return true. If the left returns false, the right expression is never executed. <expr> -or <expr> <expr> -o <expr> Returns true if one of both expressions returns true. If the left returns true, the right expression is never executed. -path <pattern> Returns true if the path of the executable matches <pattern>. <pattern> is a bash compatible wild card pattern. -ipath <pattern> Same as -path, but case insensitive. -name <pattern> Returns true if the base name of the executable matches <pattern>. <pattern> is a bash compatible wild card pattern. -iname <pattern> Same as -name, but case insensitive. -contains <str> Returns true if the path of the executable containes the string <str>. -icontains <str> Same as -contains, but case insensitive. -print Print all arguments to the called process. Returns always true. -exec <cmd> [args...] ; Executes <cmd> with [args...] as arguments. This expression must be terminated with a semicolon. You can use argument placeholders in <cmd> and [args...] (see below). This expression always returns true. NOTE: Please be aware that you may need to escape or quote the terminating semicolon to not confuse your shell. -sh <script> Interprets <script> as a shell script by invoking /bin/sh with the arguments -c '<script>'. You can use argument placeholders inside <script>. Please note that -sh only expects a single argument and not a variable list of arguments (as -exec does). Using -sh is the same as using -exec sh -c <script>. PLACEHOLDERS FOR -exec EXPRESSION Every -exec expression can use placeholders in the argument list to obtain information from the original exec call. Each placeholder starts with { and ends with }. Use { if you want to use a { in your argument list. The placeholders are replaced when the -exec expression is evaluated. Placeholder types: {n} Will be replaced with the number of arguments in the original call. {<idx>} Will be replaced with the original argument at index <idx>. Example: {1} would give the first argument. You can prepend <idx> with placeholder flags. {} Will be replaced with all arguments from the original call. Each argument is seperated with a space. You can use placeholder flags. NOTE: The executable name is also considered as argument. This means that a call like "echo test" will result in two arguments, "echo" and "test". PLACEHOLDER FLAGS
s Every argument is inserted as single argument instead of concatenating all arguments. Consider the arguments 'a', 'b' and 'c'. Without s, -exec {} ; would result in -exec 'a b c' ;, which in many cases is not what you want. -exec {s} ; howewer would result in -exec 'a' 'b' 'c' ;. q Quote every single argument. e Escape all non alpha-numeric characters. This flag is very useful when using a "sh -c <...>" in the -exec expression. Examples -exec echo {} ; with the call 'a' 'b' 'c' results in: 'echo' 'a b c' -exec echo {q} ; with the call 'a' 'b' 'c' results in: 'echo' 'a' 'b' 'c' -exec sh -c 'echo {}; {}' ; with the call 'sh' '-c' 'gcc d.c >> log.txt' results in: 'sh' '-c' 'echo sh -c gcc d.c >> log.txt; sh -c gcc d.c >> log.txt' Please note that this will not do what you may expect, as the >> is handled wrong in this case. -exec sh -c 'echo {e}; {}' ; with the call 'sh' '-c' 'gcc d.c >> log.txt' results in: 'sh' '-c' 'echo sh -c gcc d.c >> log.txt; sh -c gcc d.c >> log.txt' CHANGES TO PROCESSES
hexec will add some environment variables to the hooked processes. These are (may not be complete): LD_PRELOAD hexec adds libhexec-hook.so to the list of preloaded libraries. HEXEC_EXPR_SHM Contains the name of the internal shared memory object. HEXEC_LOG_FD Contains the file descriptor for error and -print output. Please do never modify these environment variables. Also take care when you use these variables, because the name and content of the vari- ables may change in the future. EXAMPLES
hexec -name 'gcc' -exec ccache {s} ; make Calls make, which will then call gcc several times. The executable name of each hooked process execution is tested against the file pattern "gcc" and "ccache {s}" is called each time a match is found. '{s}' will be replaced with the original (the hooked) call. In this example, a call to "gcc -o test.o test.c" would be replaced with "ccache gcc -o test.o test.c" HOW IT WORKS
TODO BUGS
I'm sure there are alot...it's still beta :) AUTHOR
hexec was written by Alexander Block http://blocksoftware.net/ If you wish to report a problem or make a suggestion then please email ablock@blocksoftware.net hexec is released under the GNU General Public License version 2 or later. Please see the file COPYING for license details. November 2008 hexec(1)
All times are GMT -4. The time now is 02:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy