Sponsored Content
Top Forums Shell Programming and Scripting Parsing special characters from variable commands Post 302884359 by joeniks on Monday 20th of January 2014 06:07:01 AM
Old 01-20-2014
Parsing special characters from variable commands

Hi,
I am fairly new to unix scripting and recently tasked with some reporting scripts.

The reporting checks several batch jobs and this is quite iterative.
Now I am trying to minimize script effort and maximize reusability as there are only slight nuances in the repetitive tasks.

For example I am herebelow trying to find the latest logfile, but for example the name is not always the same.
and other logfiles may exist in the same folder which are not interesting.
So I came up with parsing from a command (which also may differ on what you are trying to do.
now I am having some difficulty understanding why some of the parsing fails.

So I was hoping for some expert explanation, just for my understanding.

Any help would be appreciated
fyi, working in bash 3 on Solaris 11.
This fails (and I dont understand why)
Code:
#!/bin/bash
SHARED=/somesharedfiledir
m_jobstart=$SHARED/dummyfile_i_timestamped
apply_cmd_ls='ls -rat '$SHARED'/batches/var/log/ | tail -1'
apply_cmd_find='find '$SHARED'/batches/var/log/ -type f \( -name "*mainlog.log" \)-newer '$m_jobstart
function findlog {
 unset reply
 unset result
 unset apply
 reply=apply_cmd_$1
 result=`${!reply}`
 echo "result: "$result
}
findlog 'find'

obviously what I am trying to do is more complex, but I am trying to understand why it fails on the \(
This works
Code:
#!/bin/bash
SHARED=/somesharedfiledir
m_jobstart=$SHARED/dummyfile_i_timestamped
apply_cmd_ls='ls -rat '$SHARED'/batches/var/log/ | tail -1'
apply_cmd_find='find '$SHARED'/%B/var/log/ -type f %f -newer '$m_jobstart
function findlog {
 unset reply
 unset result
 unset apply
 # using $3 as a filter here
 reply=apply_$1
 apply=`echo ${!reply} | sed "s#%B#${2}#g;s#%f#${3}#g"`
 result=`$apply`
 echo "result: "$result
}
findlog 'find' 'batch1' '-name *mainlog.log'
findlog 'find' 'batch2' '-name *mainlog.log'
findlog 'find' 'batch3' '\( -name *mainlog.log ! -name *LB71*.log \)'
findlog 'ls' 'batch4'

general pointers on approach are welcome as well Smilie
thanks

Last edited by joeniks; 01-20-2014 at 08:06 AM.. Reason: typo in code2
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Variable Manimpulation - special characters

Hello- I have a variables that contains a string like this usr/pass@SCHEMA I want to extract the usr/pass part and ignore the SCHEMA part, I tried to use this ${dbconn%%@} and apparently it will not work because @ is a special character. I tried \@ and still no go. Any idea how to solve... (1 Reply)
Discussion started by: Nomaad
1 Replies

2. UNIX for Dummies Questions & Answers

Parsing special characters between C and XML..

Hi, I am getting problem in parsing special characters(Like &, > or <) in XML. I need to encode my C program and send in report format to another interface which is in XML format. I do not know how to encode these special characters in C program before sending to XML format. Please help !! (1 Reply)
Discussion started by: ronix007
1 Replies

3. Shell Programming and Scripting

Special characters in a bash variable in sed

Hello, I am trying the following: echo __CHANGEME__ >> testfile VAR1="&&&" sed -i "s|__CHANGEME__|${VAR1}|" testfile cat testfile This results in testfile containing __CHANGEME____CHANGEME____CHANGEME__ Whereas I want it to result in &&& I understand that if VAR1="\&\&\&" then... (3 Replies)
Discussion started by: linuxnewbeee
3 Replies

4. Shell Programming and Scripting

Sed special parsing

What is the shortest & right way to remove the string "" with a sed statement ? echo 'whateverwhatever' | sed ........ ? :) (2 Replies)
Discussion started by: ctsgnb
2 Replies

5. Shell Programming and Scripting

Sed failing for variable with special characters

This has been covered many times earlier but couldnt figure the issue myself. Can you please advise whats wrong on the below code I have a variable with special character ($) and am using that variable to replace another variable in file but however sed is failing to parse it correctly ... (7 Replies)
Discussion started by: sasiharitha
7 Replies

6. Shell Programming and Scripting

Replace special characters with Escape characters?

i need to replace the any special characters with escape characters like below. test!=123-> test\!\=123 !@#$%^&*()-= to be replaced by \!\@\#\$\%\^\&\*\(\)\-\= (8 Replies)
Discussion started by: laknar
8 Replies

7. UNIX for Dummies Questions & Answers

Environment Variable with Special characters

Hello all, I am facing with a problem of invoking an environment variable. If I use this command : /bin/ls -lt FILE_NM_?(20120515|20120516)??????_sas.sig | head -n1 | awk '{print $9}' It perfectly outputs the desired result. FILE_NM_20120516000000_sas.sig But if I do this:... (8 Replies)
Discussion started by: sethmj
8 Replies

8. Shell Programming and Scripting

Trouble with sed and substituting a string with special characters in variable

Hey guys, I know that title is a mouthful - I'll try to better explain my struggles a little better... What I'm trying to do is: 1. Query a db and output to a file, a list of column data. 2. Then, for each line in this file, repeat these values but wrap them with: ITEM{ ... (3 Replies)
Discussion started by: ampsys
3 Replies

9. Shell Programming and Scripting

awk match shell variable that contains special characters?

How to match a shell variable that contains parenthesis (and other special characters like "!") file.txt contains: Charles Dickens Matthew Lewis (writer) name="Matthew Lewis (writer)"; awk -v na="$name" ' $0 ~ na' file.txt Ideally this would match $name in file.txt (in this... (3 Replies)
Discussion started by: Mid Ocean
3 Replies

10. Shell Programming and Scripting

Parsing a file containing special characters

I want to parse a file containing special characters, below is a sample content of file content of file : Serial_no:1$$@#first_name:Rahane$$@last_name:Ajiyenke@@#profession:cricketer!@#*&^ Serial_no:1$$@#first_name:Rahane$$@last_name:Ajiyenke@@#profession:cricketer!@#*&^... (3 Replies)
Discussion started by: rajMjar
3 Replies
EXICYCLOG(8)						      System Manager's Manual						      EXICYCLOG(8)

NAME
exicyclog - Cycle exim's logfiles SYNOPSIS
eximcyclog DESCRIPTION
The exicyclog script can be used to cycle (rotate) mainlog and rejectlog files. This is not necessary if only syslog is being used. Some operating systems have their own standard mechanisms for log cycling, and these can be used instead of exicyclog if preferred. Each time exicyclog is run the file names get 'shuffled down' by one. If the main log file name is mainlog (the default) then when exicy- clog is run mainlog becomes mainlog.01, the previous mainlog.01 becomes mainlog.02 and so on, up to a limit which is set in the script, and which defaults to 10. Reject logs are handled similarly. If no mainlog file exists, the script does nothing. Files that 'drop off' the end are deleted. All files with numbers greater than 01 are compressed, using a compression command which is configured by the COMPRESS_COMMAND setting in Local/Makefile. It is usual to run "exicy- clog" daily from a root "crontab" entry of the form 1 0 * * * su exim -c /usr/exim/bin/exicyclog assuming you have used the name 'exim' for the Exim user. You can run exicyclog as root if you wish, but there is no need. BUGS
This manual page needs a major re-work. If somebody knows better groff than us and has more experience in writing manual pages, any patches would be greatly appreciated. SEE ALSO
exim(8), /usr/share/doc/exim4-base/ AUTHOR
This manual page was stitched together from spec.txt by Andreas Metzler <ametzler at downhill.at.eu.org>, for the Debian GNU/Linux system (but may be used by others). March 26, 2003 EXICYCLOG(8)
All times are GMT -4. The time now is 09:16 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy