Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Monday, January 23, 2012

Crontab : Email with attachment from crontab

I'm a java developer, and always try to learn something new.
I'm newbie to crontab. Was trying a task to write a data validation script using crontab.
Job in shell script is as follows
1. Get the info from config file.
2. Connect to DB
3. call a proc to validate the data and write invalid records to db utl file.
4. If file contains invalid records, mail the file as an attachment.

I could successfully write quarter to 4 steps.
The part 'file as an attachment' was reminding me that you are newbie to crontab.

Running the individual shell was working good ..email, attachment and validations..all good..but running script using crontab was not working for attachments

Googling around, could find few possible reasons and solutions for this....but nothing worked... :-(

Mail part was working correct but without attachments...... !!! ???? Why whyyy whyyyyyyy ..but no answer...

Finally, no option, I had to ask for help from my crontab expert friend (Pradip).

He suggested to put '. $HOME/.bash_profile' at the top of shell script where I had wrote '. $HOME/.profile'.

Trust friends, this worked at first go .... wowwww...

I asked him... how ?
The answer is ..running the individual shell script has access to PATH, but crontab might not necessarily have access to PATH.

So to have access to PATH, one should run '.profile' before crontab.
But I had already written '. $HOME/.profile'. then ?

It was not my default profile.. login to server..cd your /home and type 'ls -al'
You will see the default profile file.

'. $HOME/.profile' in my shell was 'copy-paste' from web :P

Thursday, March 19, 2009

.sh: /bin/sh^M: bad interpreter: No such file or directory

Error : -bash: ./run.sh: /bin/sh^M: bad interpreter: No such file or directory

Occurs when : You copy something from windows to linux and try to execute the .sh file in terminal.

Cause : Copying something from Windows to Linux converts 'line terminating characters' (crlf) from Windows to '^M' in Linux. You can see these by typing the command 'vi fileName.sh'
This can also happen to other (than .sh) files as well. So it is a good practice to follow the following solution whenever you are copying from Windows to Linux OR copying from Linux to Windows.
DOS text files traditionally have carriage return and line feed pairs as their newline characters while Unix text files have the line feed as their newline character. fromdos converts text files from the DOS format to the Unix format, while todos converts text files from the Unix format to the DOS format.

Solution : To remove these '^M', take the following action steps

1. run 'dos2unix' command from terminal. (for all .sh files)
$ dos2unix *.sh

2. If dos2unix is not installed, you can install it by
sudo apt-get install tofrodos

3) For other files you can do dos2unix by

find . -name *.java -exec dos2unix '{}' /;


where,
find - is a command to find the files
. - in current directory
*.java - is a file type in the directory from which you are running the command
-exec - execute the command reccurssively
dos2unix - command to be executed on found files
{} - file name format
; - should end with ';', but as ';' special char, prefixed with '/'

SpringBoot: Features: SpringApplication

Below are a few SpringBoot features corresponding to SpringApplication StartUp Logging ·          To add additional logging during startup...