Puppet sed and replace - sed

Im learning Puppet and currently trying to install tomcat. While trying to replace the Catalina home on the startup.sh using sed in the exec block, Im facing the below error.
Error: Could not retrieve catalog from remote server: Error 400 on
SERVER: Syntax error at '|export CATALINA_HOME=' at
/etc/puppetlabs/code/environments/production/modules/tomcat/manifests/init.pp:26:58
on node agent
Current value of startup.sh
export CATALINA_HOME="/home/john"
export JAVA_HOME="/usr"
......
.....
Expected output
export CATALINA_HOME="/home/john/apache-tomcat-6.0.44"
export JAVA_HOME="/usr/java/default"
My code snippet
.......
exec { 'modify_file':
command => "sed -i 's|export CATALINA_HOME="/home/john"|export CATALINA_HOME="/home/john/apache-tomcat-6.0.44"|g' /home/john/apache-tomcat-6.0.44/bin/startup.sh"
path => '/bin',
}
Any help is really appreciated, thanks in advance.
Also, I had went thru the puppet documents regarding path atrribute of exec block but I'm not sure why it is being used and what should be my path value in my manifest file.

Your sed expression is likely broken due to quote mismatch.
You could simplify the sed command by using:
sed -i '/CATALINA_HOME=/s,/home/john,&/apache-tomcat-6.0.44,;/JAVA_HOME=/s,/usr,&/java/default,' /home/john/apache-tomcat-6.0.44/bin/startup.sh
The expression contains 2 commands for both CATALINA_HOME and JAVA_HOME. Both commands uses the same syntax to append the required string to the variable declaration.
/<regex>/s will perform the subsitution on line with the <regex>.
The , is the command separator. I usually use / unless the pattern to search is a directory path.
& is printing the pattern space, i.e. the matched pattern.

Had you already tried using the file_line resource type of puppetlabs-stdlib module instead of doing an exec call?
You can see how it works here.
Match parameter receive the old value and will be replaced by the value of line parameter. For example:
file_line { 'catalina':
ensure => present,
path => '/etc/catalina/startup.sh',
line => 'export CATALINA_HOME=\"/home/john/apache-tomcat-6.0.44\"',
match => 'export CATALINA_HOME=\"/home/john\"',
}

Related

Remove a specific word from a file using shell script

I would request some help with a basic shell script that should do the following job.
File a particular word from a given file (file path is always constant)
Backup the file
Delete the specific word or replace the word with ;
Save the file changes
Example
File Name - abc.cfg
Contains the following lines
network;private;Temp;Windows;System32
I've used the following SED command for the operation
sed -i -e "/Temp;/d" abc.cfg
The output is not as expected. The complete line is removed instead of just the word Temp;
Any help would be appreciated. Thank you
sed matches against lines, and /d is the delete directive, which is why you get a deleted line. Instead, use substitution to replace the offending word with nothing:
sed 's/Temp;//g' abc.cfg
The /g modifier means "globlal", in case the offending word appears more than once. I would hold off on the -i (inline) flag until you are sure of your command, in general, or use -i .backup.
Thank you. I used your suggestion but couldn't get through. I appreciate the input though.
I was able to achieve this using the following SED syntax
sed -e "s/Temp//g" -i.backup abc.cfg
I wanted to take the backup before the change & hence -i was helpful.

sed repetition-operator operand invalid *****

I have text files that contain ***** in some locations. I need to replace the ***** with 9.999. This obviously came from some formatting error, but I do not have the program that created the files I now have to work with. I tried using the following command in csh:
sed -i "" 's/*****/9.999/g' *.dat
However, as I expected, I get the following error message:
sed: 1: "s/*****/9.999/g": RE error: repetition-operator operand invalid
I'm assuming this is because ***** is considered a special operator or something like that, but I can't figure out how to exempt them while using the sed command.
Does anyone have a hint that could help?
sed -E 's/\*{5}/9.999/g' file

sed command is not working properly

I'm trying to replace the word in shell script with sed -e command but its not replacing , please help on that, i have tried the below
we have separate file in /data/docs/config.log, in that file there is a word ?account for example ,
username acc, passsword acc, ?account.name
this ?account word needs to be replaced with word 'GLOBAL' using sed -e command ,
reacc = GLOBAL
sed -e "s/?account/$reacc/g" /data/docs/config.log > /data/docs/newconfig.log
but here the file newconfig.log has created with 0 size , no output written to the file , its not replacing its an empty file,
the output should be username acc, passsword acc, GLOBAL.name in newconfig.log
Being the only person who can reproduce the problem, you are pretty much on your own. There are plenty of things you can do to analyze the problem, though.
Double-check the shell. Don't have blind faith in #!/bin/sh. In cygwin for example, /bin/sh is an alias for bash. Verify with: echo $SHELL
Check permissions and file system. Do you have rights to write to the output file? Is the disk full? Does cat /data/docs/config.log > /data/docs/newconfig.log work? Test again in a different folder.
Double-check the output file. Is it really empty, or is the file system just slow with updating the file size? Is sed really finished? Test without output redirection; see if the output is dumped to stdout.
Test with a small file; one or two lines is enough.
If even that does not work, then test sed itself. Who knows, maybe you have a weird alias that hides the real sed. The most trivial filter is sed -e '', which should simply echo every line you type (just like cat without parameters). Does that work? Then try some simple patterns.
Systematically iterate between test cases that succeed and test case that fail, until you have found the breaking point. Doing so, you should be able to find the cause. Sorry, that's all I can do for you right now.
Remove spaces around =. Try after making
reacc=GLOBAL

How to find a workaround for latexdiff /latexdiff-vc on Windows on filenames containing spaces

I'm running latexdiff v 0.25 and when I attempt latexdiff-vc --svn -r "myFile with spaces.tex" I get the following command line output:
Working on myFile with spaces.tex svn: 'myFile' is not under version
control Running latexdiff 2 and only 2 non-option arguments required.
Write latexdiff -h to get help Something went wrong in latexdiff.
Deleting myFile with spaces.tex and abort
I'm assuming it's a bug where the right filename isn't passed correctly to svn. The command runs fine on names w/o spaces.
Does anyone know a workaround?
Assuming you are doing this manually, you may be able to use the 8.3 file name that you can get on the command line using dir /x.

WCAT gives error: "must specify at least one of the following parameters -run, -update, -terminate, -showclients or -setclients"

When running WCAT on my windows XP machine via the commandline I get the following error:
error: must specify at least one of
the following parameters -run,
-update, -terminate, -showclients or -setclients
The command I try to run is:
wcat.wsf -terminate -run -t scenario.wcat -f settings.ubr -s localhost -singleip -x
And is copied directly from the readme.
The problem is that in the readme, it's not really a hyphens.
If you look at the hex code, you see that the fake hyphen in the readme is 0x96, a hyphen is 0x2d
So go ahead and replace all the hyphens in the line with real ones. It will work after that.
The problem exists because of an error in the regex matching in the wcat.wsf file. For some reason the regex:
var run_regular_expression = /[-\/]run$/;
Will not match the "-run" argument
Changing it to:
var run_regular_expression = /[\-\/]run$/;
Does match the run argument.
Another option is to change to commandline call to:
wcat.wsf /terminate /run -t scenario.wcat -f settings.ubr -s localhost -singleip -x
using slashes instead of hyphens