Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
7
rated 0 times [  7] [ 0]  / answers: 1 / hits: 8585  / 3 Years ago, wed, september 22, 2021, 12:38:41

I need to figure out how to automatically insert a date and time of execution of a certain bash script file, into a txt file. Lets just say I have a bash script named backup.sh, and each time backup.sh executes, it would automatically create a txt file named Execution.txt, and within that txt file, the date and time of the execution of backup.sh would be written there. Does anyone have ideas to do this? I have Googled for some answers, but found nothing. Any help would be appreciated! Thanks in advance.


More From » bash

 Answers
6

Simply put this inside your backup.sh file:



date > Execution.txt


This will create the file Execution.txt inside the current working directory. The file will contain the current date and time (if it already exists, it will be overwritten). Of course you may specify an absolute path to the file:



date > /absolute/path/to/Execution.txt


To append to the file (instead of overwriting it), use >> instead of >, i.e.,



date >> Execution.txt

[#26365] Thursday, September 23, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
asketbridiculou

Total Points: 168
Total Questions: 116
Total Answers: 115

Location: Antigua and Barbuda
Member since Sat, Jan 28, 2023
1 Year ago
;