REGEX for a Full_PATH/Command --with-options


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting REGEX for a Full_PATH/Command --with-options
# 8  
Old 10-22-2012
Well then why is it working?

Can you give an example of what won't work?
Something like --> "command[fake_command]=/path/to/fakeCommand -p 'option with spaces' " ????

-Matt
# 9  
Old 10-22-2012
Yes, that. Because you can't nest quotes inside quotes in a shell script and expect the shell to understand it later. You asked the shell for a literal quote, and you got a literal quote, and it's not going away without a lot of effort and ugly horrid things like eval.

When you try and split it again, you won't get /path/to/fakeCommand -p option with spaces. You'll get

/path/to/fakeCommand -p 'option with spaces'
This User Gave Thanks to Corona688 For This Post:
# 10  
Old 10-23-2012
Hey Corona, thanks for the reply...

Ohh ok, I see what your saying.

The thing is with this, is that the "command" that the user will input will simply be put into a txt/cfg file as basically a literal string.
I've already had this implemented but was trying to fix up my REGEX a little more... The script inserts the "command" as-is into
the *.cfg file without any issues (*with any "options" that have quotes around them (due to having spaces) are still present
after appending
) and I am able to execute the command with all options present in the config file...

Though what your saying, I have no doubt that it's true, really won't affect me for my purposes. Since basically all I'm
really doing is appending a single line (string) into a "text" file.


For Example:
Code:
localhost:/usr/local/nagios/bin # ./checkNRPE add "command[check_testCMD]=/usr/local/nagios/libexec/check_process -w 50 -c 75 -p '/bin/dbus-daemon --system' -t cpu" comment "This is a Comment for the Command with Alias=check_testCMD"

*The Command was added Successfully to the nrpe_local.cfg File!

localhost:/usr/local/nagios/bin # cat ../etc/nrpe_local.cfg
### NRPE's Local Config File:
### ILLEGAL CHARACTERS (*separated by whitespace) -->   | ` & > < ' \ " [ ] { } ;
#   The Check Command's Alias' CANNOT contain any of the above characters...

command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
#command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
#command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200 

# Disk Space - Command is for checking Free/Used Disk Space for the Root Partition
command[check_rootPartition]=/usr/local/nagios/libexec/check_disk -w 10% -c 5% -

# This is a Comment for the Command with Alias=check_testCMD
command[check_testCMD]=/usr/local/nagios/libexec/check_process -w 50 -c 75 -p '/bin/dbus-daemon --system' -t cpu

localhost:/usr/local/nagios/bin # ps auxww | grep "[/]bin/dbus-daemon --system"
100       2357  0.0  0.0   2744   872 ?        Ss   Oct18   0:00 /bin/dbus-daemon --system
localhost:/usr/local/nagios/bin # 

If you look at the last line in the cfg file above (from the 'cat' command), you can see that my "new" command is present in the cfg
file with all it's options accounted for (including one's that were quoted)... Also notice the PIDs match from the "ps" Command's
output (above) and from the new command's output from NRPE (below).

And executing the command remotely from the Nagios Server using NRPE:
Code:
 NagiosSrv:/usr/local/nagios/libexec # ./check_nrpe -H 192.168.x.xxx -t 10 -c check_testCMD
OK: The CPU-Usage(%) is below ALL Warning Levels. PID(2357) CPU: 0.0%, RAM: 0.0%, CPU-TIME: 0 Min | CPU=0.0; Memory=0.0; PID=2357; CPU-Time=0; Virtual-Mem=2744; Physical-Mem=872

So, I think I'm ok with this the way it is for now....
Again, thank you guys for all your responses/suggestions it is MUCH appreciated!

Thanks Again,
Matt

Last edited by mrm5102; 10-23-2012 at 11:32 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sendmail K command regex: adding exclusion/negative lookahead to regex -a@MATCH

I'm trying to get some exclusions into our sendmail regular expression for the K command. The following configuration & regex works: LOCAL_CONFIG # Kcheckaddress regex -a@MATCH +<@+?\.++?\.(us|info|to|br|bid|cn|ru) LOCAL_RULESETS SLocal_check_mail # check address against various regex... (0 Replies)
Discussion started by: RobbieTheK
0 Replies

2. UNIX for Beginners Questions & Answers

Ls command options

Hi, If I want to list files with names containing a certain letter like " a " using just one ls command, is there any way of doing that? Note that it is containing a letter instead of one of the following (starting, ending with a letter or having the letter in between). what I want is to show... (1 Reply)
Discussion started by: AAAnni
1 Replies

3. Shell Programming and Scripting

Help executing command with options

Hi, I have this command in a shell script and I can get it to echo ok, but when I try to execute the command I get a "file not found" error. Which is strange because, if I copy and paste the same command at the cli it works ok. What am I doing wrong please? (16 Replies)
Discussion started by: bbbngowc
16 Replies

4. Shell Programming and Scripting

Reading command options one by one

Hi, Just some questions on the script below...? Given: bash-2.03$ command -a option1 name1 name2 ParseOptions() { local Len=${#@} local Ctr=2 #always start at 2 local Name=() local Iter=0 while ; do if <- Is this correct? so I can get the $2... (2 Replies)
Discussion started by: h0ujun
2 Replies

5. UNIX for Dummies Questions & Answers

Override options of rm command

How can i override options of rm command ?? and how can i implement my own options when we delete file using rm commad it will not delete file it has to move some folder....plz suggest some solution. (10 Replies)
Discussion started by: arun508.gatike
10 Replies

6. UNIX for Dummies Questions & Answers

Running set options from the command line and bash command

I'm reading about debugging aids in bash and have come across the set command. It says in my little book that an addition to typing set you can also use them "on the command line when running a script..." and it lists this in a small table: set -o option Command Line... (5 Replies)
Discussion started by: Straitsfan
5 Replies

7. Shell Programming and Scripting

Restricting the ls command options

Hi I want the 'ls' command to display only the file size,date modified and name of the file.What i could see with different options is this: $ls -got packagecount.csv $-rwxrwxrwx 1 393137 Aug 21 14:46 packagecount.csv Now what should be my possible... (4 Replies)
Discussion started by: sushovan
4 Replies

8. HP-UX

Linux - HP UX Command options

Just I gone with the script, I found some command's options which are not compatible with " HP-UX ". If I found any alternate commands to the following, most probably I will solve the issue here. 1. " iostat -x " --> this command's option( x ) is not available in HP-UX... (2 Replies)
Discussion started by: pk_eee
2 Replies

9. Shell Programming and Scripting

how to? launch command with string of command line options

my description from another thread... here's my code: #!/bin/bash IFS=$'\n' function OutputName() { input=$1 echo $input input=`echo "$input" | sed -e 's/.//'` input=`echo "$input".avi` output_name=$input } if ]; then echo... (5 Replies)
Discussion started by: TinCanFury
5 Replies

10. UNIX for Advanced & Expert Users

Split Command options

HI! All iam using Split command to split a large .txt file in to smaller files, The syntax iam using split -25000 Product.txt iam getting four output files but not in .txt format but in some other format , when i checked the properties the Type of the output files is Type can any... (7 Replies)
Discussion started by: mohdtausifsh
7 Replies
Login or Register to Ask a Question