Tag Archives: bash

install new #crontab from #bash script

you need to:

  1. save the current cron jobs for the user
  2. create a file with the new job description (pun intended)
  3. insert the new configuration
  4. check the new conf

1.
crontab -l > /tmp/current_cron
or, even better. append directly to your cron conf
crontab -l >> cronconf.txt

2.
the file should look like
cat cronconf.txt
*/1 * * * * /bin/ls >> /tmp/ls
*/1 * * * * /bin/touch /tmp/me

3.
Insert the new conf by calling crontab
crontab cronconf.txt

4.
check the new conf with
crontab -l

homogenization of hours and minutes with awk


~$ awk -F ' ' '{if($3=="hours") {print $2*60, "min" } else {print $2,$3}}' /tmp/sample.data
120 min
20 min
0
20 min
120 min
25 min
5 min
10 min
25 min
45 min
10 min
95 min
80 min
20 min
0
20 min

sample file

data  2 hours
data  20 min
data  0
data  20 min
data  2 hours
data  25 min
data  5 min
data  10 min
data  25 min
data  45 min
data  10 min
data  95 min
data  80 min
data  20 min
data  0
data  20 min

bash inverse wildcards

If you want to ls all BUT the .sh files:


ls !(*.sh)

Example:

tatico@tortuguita:~/codigo/python/files_keeper/random_files$ ls *.sh
random_file-clean.sh  random_file_generator.sh  random_file_spread.sh
tatico@tortuguita:~/codigo/python/files_keeper/random_files$ ls !(*.sh)
file4ShdNk  filea6uHLm  fileB4sRgx  filecdQQzj  fileLYvbHv  fileo4TKHj  fileoKaCVj  fileSxbv0v  fileTlphlz  fileYLJ43w
tatico@tortuguita:~/codigo/python/files_keeper/random_files$ ls
file4ShdNk  fileB4sRgx  fileLYvbHv  fileoKaCVj  fileTlphlz  random_file-clean.sh      random_file_spread.sh
filea6uHLm  filecdQQzj  fileo4TKHj  fileSxbv0v  fileYLJ43w  random_file_generator.sh

how to split large files

you have a 16Gb usb flash drive, but formatted on FAT, so no really large files can be copied.
you can split the files using split.

mac os:
to split only one file:
split -b 1000m large_file.mkv
to split all files bigger than 4Gb

find . -name "*.ts" -size +4G -exec split -b 1000m {} {} \;
debian:
split -b 1000M large_file.mkv
The output will be files xaa, xab, xac, …