Setlocale in a cron job - cron

I have a cron job creating dynamic files and sending emails to system users. I need to set the language within the cron job so gettext and date formats work when creating the dynamic emails.
I cannot set the LANG in the /etc/environment file because the language is not static. Lets say the cron sends 10 different emails to 10 users - each could have a different language.
When I run my script in a webpage where I can set the session variables with
putenv("LC_ALL".LANG);
setlocale(LC_ALL,LANG.".utf8");
Everything works great. I am guessing since the cron doesn't create a session, these are ineffective.
Any ideas on how I can set this variable dynamically within a cron?

Figured it out. I forgot to bindtextdomain. It is something that is automatically done on the website but I added it to the cron script and all is well.

Related

How to stop cron job after job is done programmatically

I am creating an app using magento 2 where user is supposed to upload csv file containing:
Name of base image
Name of clipart
height
Width
top margin
left margin
using above data I am suppose to combine both the images.
I am using cronjob to finish up this task, like as soon as user clicks on generate images first I am inserting all data into database and then using cron job, combining all the images after each minute.
The problem is cron job is still inserting data even after it has finished combining images. I want to stop cron job as soon as it finishes the task.
can I run cron job based on some condition or something?
The cron job always run by a schedule, so you have to add your condition within your code. Something like this:
if($this->isCombined()){
return false;
}
Cheers

Execute SQL job based on excel or text file message

We have a SQL Server Agent job, which we need to run manually based on user/s request. The request is random and unfortunately, we cannot predict when the users will request it. Also, we have to it in after hours (Plus, it takes over an hour to run).
Anyways, I wanted to see if it was possible to run this job automatically based on a text file we can put on a Share drive. Users can update this file to say "Run" or "Stop" along with a few parameter values. I could setup a schedule to run daily and if the status changes to "Run" then the job runs for day/s until the text file is updated to say "Stop".
You can create and extremely simple small desktop for the user, where they can start Run/ Stop the job (simple C#, connect to database and execute job with the name of the job).
You can create a power shell script which will look for a file (text file) and depending on the value will run/stop the job.

Starting with Email-ext plug-in

problems using Email-ext
using groovy/jelly script(Default)
Fail to send emails
attachment pattern doesn't work
solution to above problems:
1.create a new job in jenkins and make a note of your job workspace plays an important role.
Email-ext comes with some ready made default scripts which we can use to send emails with attachments.
place the scriptname you are using inside defalut contents use the pattern below
{script,template="nameofthetemplate}
2.make a note that there are no commiters option in this plug-in infact use triggers and send emails to recipents list by selecting one of the options a.developers b.culprits c.recipentslist d.requestors
3.This is the critical point because attachment section in jenkins use Ant script.so Ant script work mainly on realtive addressing rather than absolute addressing.
so content in attachment pattern should be some thing like this
**/foldername/*.txt
(anyextension)
Note:make sure the floder exists in your job workspace
Hope this helps to some extent

VBScript: Extracting data from a spreadsheet to import it into a config file

A little background on what I need assistance with. I am currently working on a project that is requiring the configuration of over 500 Cisco 2911 Routers. Part of the job is to take a premade config file provided by our customer and make it location specific. That involves changing the hostname and the second and third IP octets.
I have recently made a script that will actually configure the device but now I need to make another script that will make the changes in the default config file and save it location specific. The goal is when they launch the script, it will prompt for the location, open the config file, change the hostname, open a spreadsheet containing an IP calculator, look for the location, extract the IP from it, plug it into the necessary location, then save it location specific and allow my first script to run.
Until about a week ago I have done little to no coding for over a decade so I am rusty and my knowledge is not that great. Any assistance would be greatly appreciated.
Too much to type in here but lets make it simple for you.
Do a CSV file with hostname, Interface1, IP1, Mask1, Interface2, IP2, Mask2, Location, etc..
try to put all the data that you will need for each device on a single raw on a CSV and the using python, pexpect or telnet modules and some bash you could be able to do all of that on just one script.
Will be a lot of work but at the end you will have a script that will help you on future global configs like this one for +500 devices.
Use this sites as reference:
http://linux.byexamples.com/archives/346/python-how-to-access-ssh-with-pexpect/
http://pexpect.sourceforge.net/doc/
I did one with those same tools that I mentioned and it runs commands on +1000 different cisco routers, switches and ASA and print on screen a report at the end.
Try with those tools.
Regards,

A Batch File which contains a Lotus Script

Is it possible to run a batch file containing a lotus script? Would it also be possible to include a lotus script and then another language for example ksh's? If yes then could you please give me some samples or tutorials on how to do it?
What I need to do is this:
There is already an existing batch file which contains a ksh's that updates the value in an excel files every time it is executed.
What I need to do is include two new functions, first I need to download the excel file from a rich text in a document of lotus notes, then run the functions above written in ksh's after that
I need to re-upload it or update the excel file which is in the lotus notes document. I used lotus script for the added functionality.
I also don't know how to use or create ksh's and batch files. Thanks.
I personally would turn around the logic: why not use a scheduled LotusScript or Java- Agent, detach the file from the richtextitem and then run the ksh from there (e.g. using the Shell- Command of LotusScript)...
That way you can code the stuff you need in the languages that are best for your purpose. You could even attach the ksh to a configuration document and detach it on the fly Or build the ksh completely on the fly (with write commands)... That makes this solution replicate to any number of servers without having to distribute your ksh to each of them...
LotusScript runs only within a scripting host engine provided by IBM Lotus, but LotusScript isn't the only way to access Lotus Notes data.
You haven't said what platform you are running ksh on. You mention that you are operating on Excel files, so if you are running your scripts on Windows it may be possible for you to use the Lotus Notes COM classes. Those classes are almost exactly the same as the back-end classes that you would have available in LotusScript, but I have no idea whether any version of ksh (not to mention whatever version you are using) supports the CreateObject call or any other way to access COM classes.
However, a ksh script can certainly run Java programs, and there are Java classes for Lotus Notes that are (again) almost exactly the same as the back-end classes that you would use in LotusScript. It seems to me that the obvious thing for you to do is write a small Java program to retrieve the file from the Domino server, and another Java program to re-upload it after. Then have your script run the program to do the download, run the commands to modify the Excel data, and then run the program to do the upload.

Resources