Update -XX:MaxPermSize to -XX:MaxMetaspaceSize via batch file - batch-file

Our installer updates our application from using java7 to java8. In doing so, we'd like to update their Tomcat7 configuration to limit the Metaspace at the same level as their PermGen space (which they might have customized). So if they had...
-XX:MaxPermSize=256m
we'd like to set...
-XX:MaxMetaspaceSize=256m
The trick is, the installer must do this via a batch file. (Perhaps querying Tomcat with some command that would spit out the present value to a file, and then read that value in, and then fire off another command to set the value.)
If I can get the present MaxPermSize, I know that last piece of the puzzle:
"%TOMCAT7_EXE%" %SERVICE_NAME% --JvmOptions "-XX:MaxMetaspaceSize=%MAX_SIZE%"
(It might also be nice to remove the no longer applicable MaxPermSize, but that would be just for extra-credit.)

Related

Shake: automatically deleting file after failed command

Using Shake, to create an mp3 (this is just a learning example), I use lame, and then id3v2 to tag it.
If the lame succeeds, but the id3v2 fails, then I'm left with the mp3 file in place; but of course it is "wrong". I was looking for an option to automatically delete target files if a producing command errors, but I can't find anything. I can do this manually by checking the exit code and using removeFiles, or by building in a temporary directory and moving as the last step; but this seems like a common-enough requirement (make does this by default), so I wonder if there's a function or simple technique that I'm just not seeing.
The reason Make does this by default is that if Make has a partial incomplete file on disk, it considers the task to have run successfully and be up to date, which breaks everything. In contrast, Shake records that a task ran successfully in a separate file (.shake.database), so it knows that your mp3 file isn't complete, and will rebuild it next time.
While Shake doesn't need you to delete the file, you might still want to so as to avoid confusing users. You can do that with actionOnException, something like:
let generateMp3 = do cmd "lame" ... ; cmd "id3v2" ...
let deleteMp3 = removeFile "foo.mp3"
actionOnException generateMp3 deleteMp3

Check if a file exists in UNIX from SQLplus without UTL_FILE

My current scenario is like this:
I need to login to sqlplus from a shell script to call a stored procedure.
After that I need to create a CSV file by SPOOLING data from a table.
Then I need to check whether the CSV file has been created in a particular directory and depending on the result an update query needs to be run.
I know that this can be checked within sqlplus with the help of UTL_FILE package but unfortunately due to Client policies,the access of this package is restricted in the current system.
Another way is to exit from sqlplus and perform the file check in UNIX and then again log in to sqlplus to perform the rest actions. But this I believe would result in slower execution time and performance is an important factor in this implementation as the tables contain huge volumes of data(in millions).
So is there any other way to check this from sqlplus without exiting from the current session?
System Info:
OS - Red Hat Enterprise Linux
Database - Oracle 11g
If the file is on the same machine that you're running SQL*Plus on, you could potentially use the host command.
If the file you're checking is the same one you're spooling to, it must exist anyway, or you would have got an SP error of some kind; but if you do want to check the same file for some reason, and assuming you have a substitution variable with the file name:
define csv_file=/path/to/spool.csv
-- call procedure
spool &csv_file
-- do query
spool off
host ls &csv_file
update your_table
set foo=bar
where &_rc = 0;
If the file exists when the host command is run, the _rc substitution variable will be set to zero. If the file doesn't exist or isn't readable for any reason it will be something else - e.g. 2 if the file just doesn't exist. Adding the check &_rc = 0 to your update will mean no rows are updated if there was an error. (You can of course still have whatever other conditions you need for the update).
You could suppress the display of the file name by adding 1>/dev/null to the host command string; and could also suppress any error messages by also adding 2>/dev/null, though you might want to see those.
The documentation warns against using &_rc as it isn't portable; but it works on RHEL so as long as you don't need your script to be portable to other operating systems this may be good enough for you. What you can't do, though, is do anything with the contents of the file, or interpret anything about it. All you have available is the return code from the command you run. If you need anything more sophisticated you could call a script that generates specific return codes, but that's getting a bit messy.

Using bukhantsov.org command line query output with options

I am trying to use the tool here business objects query builder output
And there are virtually no examples, so I'm struggling to make it work. It produces no errors, but outputs no file in the directory where the batch file is, that I can see.
Here is the code inside querybuilder.bat:
set lib=c:\Program Files\Business Objects\Common\4.0\java\lib
java -cp "querybuilder.jar;poi-3.8-20120326.jar;%lib%\*" org.bukhantsov.querybuilder.Program %*
Here is the code inside what I am running, which I've named RunQuery_ALLACTIVE.bat, except of course with my Server, Username, and Password changed for the purpose of this post.
I have this all on one line, with no line breaks.
querybuilder.bat -cms:SERVER -username:OURUSERNAME -password:OURPASSWORD -query:"SELECT * FROM CI_INFOOBJECTS where SI_SCHEDULE_STATUS = 9 order by SI_NAME" -auth:windowsad -excel "Output.xls"
Can't tell if the - options go on different LINES ?
Can't tell if I'm supposed to put output file in quotes, or if it should be an existing file or not?
can't tell if for Windows AD (which we use), I would put "Windows AD" or WindowsAD, I'm assuming no spaces obviously.
Tons of unanswered questions on this tool - it LOOKS cool, but has anyone actually successfully used it? Can't really find comments or history on the 'net..
To answer your questions:
The options go on the same line, not on different ones
As Joe said, you'll need to specify the output file as -excel:"Output.xls"
If you want to use Windows AD, you'll probably need to specify secWinAD (case-sensitive).
If you're not sure about the command line options, I suggest you build up gradually: first only specify the required options, then add the optional ones one by one so you know which one is giving you problems.
Also, I noticed that the download page contains a version compiled for XI3.x and BI4. Make sure you use the correct version, corresponding to the version of BusinessObjects you're using. Also, verify the path in the batch file to see if it points to a valid folder containing the JAR files for the BusinessObjects environment.
Update:
I just noticed that the same author/developer created another application (GUI, not command line) that might be a bit easier to use. Have a look here.

Multiple commands on Nagios remote host

I have a machine monitored by nagios that has the following line in nrpe.cfg
include_dir=/etc/nagios/cfgs/
The 'cfgs' dir consists of following files with various commands.
servers.cfg
database.cfg
regular.cfg
However, some commands are repeated among these cfg files but they differ in the arguments. Eg: check_disk command on database has different threshold and on servers have different threshold for the same command.
My question is: If there are multiple definitions of a command, which command is picked up by nrpe? Is there some way to identify it?
You generally can not have duplication in command names in your nrpe.cfg files - though no error is thrown if there are duplicates. I've had this happen before (accidentally) with very large configs, and nrpd has always chosen to use the very LAST matching command it found. In my case, being a single config file, it was always easy to spot the LAST matching command in the file. With many included files, this could be an issue. I believe it would load these files in alphabetical order with the include_dir command you provided.
In any case, I'd look for more unique names for these duplicates. Such as 'check_disk_db' for the one checking database disks. These names can be just about anything you want them to be - but remember to change them on the Nagios side as well. Using unique command names would make your life as a Nagios admin much easier.
As far as figuring out which is actually being used. You can turn on debugging. The debugging output doesn't include the file the command came from, but does show you what options were passed and exactly which actual commands where executed via the check command. This info should be enough to see which nrpe command was selected.

exec ant replace a value in a .m file

how to write an exec task in ant to replace two values in .m file.
Because I want to replace the version number in iphone app, including my build number which i build using hudson, i remotely access the macos and get the app to be copied on to my windows
system, so i generated the build using ant exec tasks, but now i want to replace my build number into the concern file before compiling,
so how can i use exec task to replace certain values in a file.
I know propertyfile task which replaces the value in a property file, but it doesn't work for
this.
If you have a template file, you can use the <copy> task with a nested <filterset> to replace certain values. If not, you can still use <copy>, this time with a nested filter chain containing a <replaceregex> token filter. If you want to edit in place, you can move the newly created file to the old location afterwards.
The use of <exec> is almost certainly a bad idea for your application, as it would make your build rely on external applications which usually are not available on all platforms, thus breaking portability of your build.

Resources