Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash script write without overwrite? [closed]

Tags:

linux

bash

cron

I want to test a crontab job by writing the date to a text file every minute as the following script shows:

#!/bin/bash
date >> /home/SomeUserName/Desktop/date.txt

This almost accomplishes what I want but I don't want my script to overwrite the file in each iteration. So I used >> instead of > because I thought that it would only append to the file. Although, every time crontab executes the script I can only see one date.

Why is that so happening?

I am using linux mint.

like image 700
afwef1 Avatar asked Jun 01 '26 22:06

afwef1


1 Answers

I can confirm that it should work as expected.

Created a script /home/myuser/xd.sh:

#!/bin/bash
date >> $HOME/date.txt

and a crontab (via crontab -e):

# m h  dom mon dow   command
  * *  *   *   *     /home/myuser/xd.sh

Then I see the expected result:

$ cat date.txt 
Sa 16. Jul 02:02:01 CEST 2016
Sa 16. Jul 02:03:01 CEST 2016
Sa 16. Jul 02:04:01 CEST 2016
Sa 16. Jul 02:05:01 CEST 2016
Sa 16. Jul 02:06:01 CEST 2016
Sa 16. Jul 02:07:01 CEST 2016
like image 107
Stefan Kamphausen Avatar answered Jun 03 '26 18:06

Stefan Kamphausen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!