Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Have a file with pull-requests details and has CreatedDate (ex: 1613698170) is in Unix timestamp format.
I want to notify to stake holders, when pull-request is open more than x days.
How to get the no of days between current date and pull-request created date in bash / groovy. So that I will execute this script in jenkins and send out notifications.
The following code:
def epochMillis = 1598098239000
def now = new Date()
def then = new Date(epochMillis)
def days = now - then
println "then: $then"
println "now: $now"
println "days between now and then: ${days}"
calculates the number of days between now and epoch millis. When executed, the above prints:
─➤ groovy solution.groovy
then: Sat Aug 22 14:10:39 CEST 2020
now: Fri Feb 19 19:01:54 CET 2021
days between now and file creation: 181
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I want to establish the amount of time that has passed since 24th February 2008 - time 17:28 UTC
The output would be something like:
Its been x years x months x days x hours x minute x seconds since Tottenham Won a Trophy
You can use python:
python -c "from datetime import datetime as d; print(d.today() - d(2008, 2, 24, 17, 28, 0))"
Or you have to build something like:
starttime=$(date -d "2008-02-24 17:28 UTC" +%s)
current=$(date +%s)
timediff=$((current - starttime))
echo $timediff
days=$((timediff/86400))
hours=$((timediff%86400/3600))
min=$((timediff%3600/60))
sec=$((timediff%60))
echo "$days days $hours hours $min minutes $sec seconds since start"
Years and month would be more difficult
This question already has answers here:
Pipe string to GNU Date for conversion - how to make it read from stdin?
(5 answers)
Closed 4 years ago.
The community reviewed whether to reopen this question 11 months ago and left it closed:
Original close reason(s) were not resolved
Assume we have a timestamp like below:
[xxxxxx ~]$ date -d#1530586185
Tue Jul 3 05:49:45 EEST 2018
and I want to pipe it to date like:
echo 1530586185 | date -d#
date: invalid date ‘#’ <-------- error message
How can I do it?
Suggestion 1:
date -d"#$(echo 1530586185)"
Suggestion 2:
DATE=$(echo 1530586185); date -d"#$DATE"
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm creating a program that pulls information from a who command, see also this question to see the format of the who command.
Now what I want to do is ssh to different servers and run the who command. Problem being I have no idea how to ssh in Ruby. I'm aware of require 'net/ssh/gateway' would somebody mind giving me an example of how I can ssh in Ruby and and perform a who command (like the linked question) on multiple servers?
For example:
def user
cmd = `who`.gsub(/[ \t].*/,"")
puts cmd
#<= Do some fancy stuff that will ssh to the servers and run cmd
end
Thank you ahead of time.
I've found out that doing something like this:
26 print "Enter password: "
27 system "stty -echo" #<= Removes echo from typing, you won't see your keystrokes
28 #password = gets.chomp
29 system "stty echo"
30
31 def logged_in
32 cmd = `who`.gsub(/[ \t].*/,"")
33 check = Net::SSH.start(#host, #username, :password => #password)
34 check.exec!(cmd)
35 end
36
37 #host = %w(servers).each do
38 logged_in
39 end
40
41 #username = Etc.getlogin
Will do what I want to accomplish.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I want to get the name of the users which executed a command (for example cat).
fc -l will provide a list with the most recent commands executed by the current user but is there an way to find out the history for all users?
I read the manual but i could not find something that would help
Do you know any other commands which would do this job?
I also tried w and who
I found this solution: the super user will search in each dir from "home" in the .bash_history and make a grep on that file for that command. It will work but is this optimal?
Using awk =)
awk -v monitoredcmd=cat '
$1~"^#[0-9]{10,}\s*$"{
sub(/#/,"")
tmpdate=$1
}
$1==monitoredcmd{
"date -d #"tmpdate | getline date
close("date -d #"tmpdate)
print "command [" $0 "] by",
gensub(/\/home\/([^\/]+).*/, "\\1", "", FILENAME),
at,
date
}
' /home/*/.bash_history
Sample Output
command [cat file.txt] by sputnick mer. févr. 13 15:34:44 CET 2013
command [cat l.py] by sputnick mer. févr. 13 15:45:38 CET 2013
command [cat foobar.pl] by marc mer. févr. 13 15:47:54 CET 2013
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm building a shell script that is checks the existence of log files in a loop. The log files I'm trying to open are named like this: access_log-%02d00-%02d59 with %02d being an hour. In perl I could just say "access_log-${hour}00-${hour}59". But how do I do that in shell script? Here's my code. It doesn't work because it thinks the var name would be $HOUR00 and $HOUR59.
for HOUR in 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23; do
if [ -e tmp/access_log-$HOUR00-$HOUR59 ]; then
# do stuff here
fi
done
I figured it out myself. I works just the same as in perl. ${HOUR}00 does the trick.