shell script to create file with latest mod time of any other files in directory

My VPS running Plesk, in git settings of a repository on the site, offers an 'enable additional deployment actions' with a box to put shell command statements line-by-line. I'd like to have it create a file in a directory via touch with the mod time of any other file with specific extension (e.g. '.js' /'.css') in that directory so an outside script can examine that (e.g. latest.js / latest.css) for comparison by other code. If this isn't possible or convenient, I must to resort to a frequent 'scheduled task' to do this operation. Thanks for any help! πŸ™‚
2 Replies
Dracon
Draconβ€’4w ago
You can add this script to the 'additional deployment actions' in your Plesk Git settings. Here's a sample script that does just that: #!/bin/bash # Navigate to the directory containing the files cd /path/to/your/directory # Find the latest file with a .js or .css extension latest_file=$(ls -t1 | grep -E "\.js$|\.css$" | head -n 1) # Check if a file was found if [ -n "$latest_file" ]; then # Use 'touch' to create a new file with the same modification time touch -r "$latest_file" latest_file_indicator else echo "No .js or .css files found in the directory." fi Replace /path/to/your/directory with the actual path to your directory. This script will create a file named latest_file_indicator with the modification time of the latest .js or .css file.
ProdJuan
ProdJuanβ€’4w ago
looks like that can be adapted to fit my use case (js and css files are in separate directories), just cd to each respective directory and do the latest_file + touch statements and it's a 3-line solve. Nice! πŸ‘