All Questions
36 questions
2
votes
2
answers
3k
views
Script - Compare filename date with current date
I'm trying to compare a file with date in its name to the current datetime of the system:
Filenames are with the following format:
FileName.yyyymmdd.hhmm.file (e.g. File156tr.20220914.0958.txt)
I have ...
1
vote
4
answers
917
views
Given a weekday name, week of a month, and a year, how to find the date
I can find the last Monday using date -d 'last-monday' +%F but given a weekday name, week of a month, and a year, how to find the date?
e.g. given: Monday, Week 4, June, 2022
output: 2022-06-20
given: ...
0
votes
2
answers
685
views
date validation for a custom format in shell
i am writing a generic script for the custom format date validation .
here is the script
dateformat=$1
d=$2
date "+$dateformat" -d "$d" > /dev/null 2>&1
if [ $? != 0 ]
...
1
vote
1
answer
9k
views
Getting file with today date from SFTP
How would you go about getting a file from a SFTP server if the file has today date in the name of file?
I know the mget and get command is used to pull the file over, but I can't seem to find ...
4
votes
2
answers
3k
views
Sort an output by year month and date
I want to sort the output below by year, month and date. I tried a few combinations that don't seem to be working.
In the below output 2nd column is the date, 3rd is the month and 4th is the year.
I ...
0
votes
2
answers
3k
views
Taking an integer and creating a date format
I can take a date and convert it to an integer.
date_as_integer=$(echo "2020-06-13" | sed "s/-//g")
So I can do some math on it such as:
day_before=$(( date_as_integer - 1 ))
...
0
votes
3
answers
1k
views
Displaying time and date next to part of the ping output
#!/bin/bash
ping -c 1 8.8.8.8 | awk '{print $7}'
date
So for the code above, I want it to display the date and time in this format below
Tue May 5 11:11:11 UTC 2020 time=0.838 ms
So far it prints ...
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"
# ...
0
votes
2
answers
2k
views
how to add time from string with %Y%m%d%H%M%S format
look at my shell script
#!/bin/sh
aaa=20200101101010
bbb=$(date -d "$aaa -5 minutes" +'%Y%m%d%H%M%S')
echo $bbb
i want to get:
20200101100510
but result is:
20200101101009235500
what happend?
How ...
0
votes
3
answers
6k
views
How to add time to a date variable in linux?
tried this but failed
now=$(date +%Y%m%d%H%M%S)
past=$(date +%Y%m%d%H%M%S -d "${now} -5minutes")
echo $past
result:
date: invalid date ‘20200120175610 -5minutes’
TT
0
votes
2
answers
3k
views
spaces between date format
what's the best way in shell to create custom date format and adding any space between the format?
For example the below command for print yesterday date by the format Oct 9
custom_format="$(date ...
0
votes
2
answers
459
views
Bash Time Difference
I have a log file and I need to make some calculations between two jobs to find time difference.
In my log file I am supposed to calculate time between the jobs incoming request and candidate list ...
1
vote
1
answer
728
views
bash next month error
Running into errors. I am trying to get the next month when a user sends a date in.
D="2019/12/01";
D=$(date -d "$D");
echo "Current Date = $D";
prints Current Date = Sun Dec 1 00:00:00 EST 2019
...
0
votes
2
answers
333
views
List lastest modified or newly created files in linux
How to list modified or newly created files or directories in linux. So that I can trigger another command or shell script for another task.
for eg. A file a.txt and test.txt are modified and I ...
1
vote
2
answers
570
views
script with date work on Linux but not on AIX
I wrote a script to that works fine on Linux but fails on AIX 7.2.
My script uses the command date with -d.
The purpose of this script is to get the last day that is not a Saturday, Sunday or a ...