Posts Tagged ‘sh’
Linux | Shell Script : Compare File Last Modification Date
test is a very useful command in Linux, esp when you’re writing a shell script.
There is some very useful function the test can do it for you easily.
Today, I would like to introduce the powerful tools in test to do file’s last modified time comparision.
The keyword is -nt and -ot. Both command required 2 inputs to be place before and after the keyword,
eg: FILE1 -nt FILE2.
-nt indicates that FILE1 is NEWER (modification date) than FILE2.
-ot indicates that FILE1 is OLDER (modification date) than FILE2.
Here is a sample yet complete shell script to describe it..
#!/bin/bash
file1=newer_file.txt
file2=older_file.txt
if test $file1 -nt $file2
then
echo "$file1 is NEWER than $file2"
else
echo "$file1 is OLDER than $file2"
fi
Linux | Run backend process
to run a linux backend process :
$> nohup ./start.sh &
bad interpreter – no such file or directory
I hit this error recently “bad interpreter – no such file or directory” when I trying to run/execute a shell script in linux box. The shell script is quite simple, just to initialize a java class.
This “bad interpreter – no such file or directory” is cause by the line-feed / carriage-return issue among windows-linux OS. The shell script is initially written in windows before I ftp it into linux box and run.
To solve it, is very simple — dos2unix.
$> dos2unix my-script.sh
The dos2unix is DOS/MAC to UNIX text file format converter (according to linux manual). It helps to solve the CR/LF conflicts between windows and *nix.
Besides, do remember to do another command to make an .sh file executable in linux — chmod.
$> chmod +x my-script.sh