New answers tagged

0

If your epoch time is in milliseconds instead of seconds, remove the last three digits before passing it to date -d: $ date -d @1455086371603 Tue Nov 7 02:46:43 PST 48079 #Incorrect This gives incorrect data. Remove the last three digits. $ date -d @1455086371 Tue Feb 9 22:39:31 PST 2016 #Correct after removing the last three digits. You may ...


1

Try this $ date -d @1469411110 Sun Jul 24 21:45:10 EDT 2016 $ date -d @1469411110 '+%F +T' 2016-07-24 21:34:36 EST 2016 $ date -d "$(date -d @1469411110)+10 days" Wed Aug 3 21:45:10 EDT 2016 $ date -d "$(date -d @1469411110)+10 days" +'%F %T' 2016-08-03 21-45-10


0

One liner: stat -c %Y /path/to/file | echo `expr $(date +%s) - $(cat)`


2

#!/bin/bash NOW=$(date +"%s") SOON=$(date +"%s" -d "3:00 PM Sun") INTERVAL=$(($SOON-$NOW)) sleep $INTERVAL GNU date allows you to specify the format of the output, as well as the date to display. So I use the format string "%s" to get the time in seconds since the epoch, and the same for the arbitrary time using the -d paramater. Get the difference, and ...


7

if the user is allowed to use at command, this is the perfect use for that: $ at 08:00 022116 at> myscript.sh at> <----------- ctrl-d here job 9 at 2016-02-21 08:00 if you get a message like "user blah is not able to run at", ask the syadmin to add this user to at.allow file or remove from at.deny file, depending on how it is used in your ...


4

Here is a solution built around the inotifywait utility. (You could use incron too, but you'd still need code similar to this.) Run this at boot time, for example from /etc/rc.local. #!/bin/bash # cd /path/to/samba/folder # Rename received files to this prefix and suffix prefix="some_prefix" suffix="pdf" inotifywait --event close_write --format "%f" ...


0

I think cron is a good idea! Here some input for your script: #!/bin/bash smbdir="@sambadir@" # change the @sambadir@ variable by hand smbsubdirs=(A B C D) smbprefix="@sambaprefix@" # for example for sd in ${smbsubdirs[@]}; do ssd=$smbdir/$sd && [ -d "$ssd" ] || continue for f in $(find $ssd -cnewer $ssd -type f); do if [[ "$(basename $f)" ...


4

Month names are not tied to a timezone, but to locale. $ LC_ALL=cs_CZ.utf8 date +%B leden $ LC_ALL=es_ES.utf8 date +%B enero


2

This will run a find command that outputs a shell command moving the file in a directory based on the last change time of the file. It will create the target on the directory on the fly (which may complain it it already exists). The generated commands are then directly piped into a shell interpreter. find -maxdepth 1 -type f -printf "mkdir -p %CY/%Cm/%Cd ; ...


0

With gnu sort having input.txt as input (explain): cat input.txt | sort -t _ -k6n,6.4 -k2M -k3n -k4.1n,4.2 -k4.4n,4.5 -k4.7n,4.8 Add --debug flag to see fields used for sorting. Useful when you have to tweak substrings: Wed_Dec_30_16:00:41_PHT_2015.zip ____ ___ __ __ __ __


0

I know you have your data in an array , but I tested with a file. Shouldn't matter - logic is the same. Just convert to seconds since epoch, test which epoch number is biggest, and remember that number - thats your most recent date. Then obviously you need to reconcile that string against your file structures to get the specific file you were looking for. ...



Top 50 recent answers are included