Skip to main content

All Questions

0 votes
1 answer
234 views

Display time logged in by hour(s) and minute(s)

I am writing a script to display how long a user has been logged in. who | grep "$userid" | awk '{print $1,$3,$4}' | while read user time; do \echo $(($(($(date +%s) - $(date -d "$time" +%s)))/60)) ...
Derek's user avatar
  • 11
0 votes
2 answers
130 views

How can this shell script (no bash) display seconds as DDD:HH:MM:SS?

#!/bin/sh INTERVAL=12 TOTAL=3388888 DURSECS=$(($TOTAL * $INTERVAL)) printf "\n$DURSECS seconds.\n" printf "\nFormatted as DAYS:HOURS:MINUTES:SECONDS - DDD:HH:MM:SS - the total duration will be:\n" # ...
almadinedotnet's user avatar
0 votes
2 answers
4k views

change date/time format from yyyymmddHHMMss to dd/mm/yyyy HH:MM:ss

How do I change date/time format from yyyymmddHHMMss to dd/mm/yyyy HH:MM:ss which is displayed as an output (eg. JOBNAME1 STARTED AT 20180904152402) from a command... grep JOBNAME1 | sed -e s/|/ /...
Colin's user avatar
  • 1
1 vote
3 answers
2k views

Checking whether a date is within the next week

Trying to create a script for automatic SSL renewal with LetsEncrypt. Daily script begins with checking when SSL expiry is: response="$(openssl x509 -enddate -noout -in ~/letsencrypt/www.mydomain....
DDiran's user avatar
  • 115
-1 votes
3 answers
1k views

Working with dates

I have a task to do for which i am able to think of logic but unable to implement in Unix. I have a directory in which its sub-directories are having there naming pattern as 'mmddyy'. So my task here ...
Somesh Pursnani's user avatar
1 vote
1 answer
10k views

Difference between two dates on Linux

I'm getting a date in the format of v_date=$(date +"%Y%m%d" -d "1970-01-01 + $(stat -c '%Z' file ) secs") v_sysdate=$(date +%Y%m%d) echo "$v_date" 20150907 echo "$v_sysdate" 20150907 ...
VRVigneshwara's user avatar
2 votes
1 answer
3k views

How to test for number smaller than other number

I have a script that goes like this: while : do Start_Time=$(date +"%s") MAIN PROGRAM GOES HERE (CROPPED TO SHORTEN THINGS) Run_Time=$(( $(date +"%s") - $Start_Time )) if [[ $...
TCZ8's user avatar
  • 1,099
5 votes
2 answers
2k views

Create sub-directories and organize files by date from file name

I have been using the following script to organize my photos into "Date' Directories: for x in *.JPG; do d=$(date -r "$x" +%Y-%m-%d) mkdir -p "$d" mv -- "$x" "$d/" done This script works great. ...
Wags's user avatar
  • 317
0 votes
2 answers
142 views

Executing a program according to the last modified date

I need to write a script which would execute some executables in a directory according to the last modified date. The oldest should run first. How do I do it? This is what I have done so far for f ...
DesirePRG's user avatar
  • 265
11 votes
2 answers
11k views

Create sub-directories and organize files by date

I have some directories of files copied from my security camera that I would like to organize into sub-directories by file date. So for example; -rwxrwxrwx 0 root root 4935241 Jul 19 2012 DSCN1406....
Richard Ahlquist's user avatar