Name of the users which executed a command [closed] - bash

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

Related

Get currency exchange rate using bash [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed last year.
Improve this question
I would like to display the current exchange rate from the currency euro to us dollar in the command line using bash shell script. I'm using the website market insider.
I saw on someone's blog to use wget command
wget -qO- https://markets.businessinsider.com/currencies/eur-usd
But how can I display only the rate? Desired output (example for current rate 1.1347) --> 1.1347 $
PS: I would prefer not to use API
Any help would be appreciated
Do this cleanly using their API:
#!/usr/bin/env bash
API='https://markets.businessinsider.com/ajax/'
ExchangeRate_GetConversionForCurrenciesNumbers() {
isoCodeForeign=$1
isoCodeLocal=$2
amount=$3
date=$4
cacheFile="/tmp/$date-$amount-$isoCodeForeign-$isoCodeLocal.json"
# Check if we have cached the result to avoid front-running the API
if ! [ -e "$cacheFile" ]; then
post_vars=(
isoCodeForeign="$isoCodeForeign"
isoCodeLocal="$isoCodeLocal"
amount="$amount"
date="$date"
)
method='ExchangeRate_GetConversionForCurrenciesNumbers'
IFS='&' url="$API$method?${post_vars[*]}"
curl -s -X POST "$url" > "$cacheFile"
fi
jq -r '.ConvertedAmountFourDigits' "$cacheFile"
}
getRateEURO_USToday() {
ExchangeRate_GetConversionForCurrenciesNumbers EUR USD 1 "$(date '+%Y-%m-%d')"
}
# Set LC_NUMERIC=C because the float format returned is using . as decimal
LC_NUMERIC=C printf 'The exchange rate for EUR to USD today is: %.4f\n' \
"$(getRateEURO_USToday)"

Get the days between two dates which are in Unix Timestamp [closed]

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

what does this command line do? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I am working through this resource: https://cmdchallenge.com
On the following challenge: https://cmdchallenge.com/s/#/search_for_files_containing_string, the problem was:
Print all files in the current directory,
one per line (not the path, just the filename)
that contain the string "500".
When I ran:
ls -al
I got the following:
total 36
drwxr-xr-x. 2 501 dialout 4096 Feb 10 21:08 .
drwxr-xr-x. 39 501 dialout 4096 Apr 18 19:04 ..
-rw-r--r--. 1 501 dialout 204 Apr 29 17:44 README
lrwxrwxrwx. 1 501 dialout 23 Feb 10 20:59 access.log -> ../../common/access.log
lrwxrwxrwx. 1 501 dialout 25 Feb 10 21:08 access.log.1 -> ../../common/access.log.1
lrwxrwxrwx. 1 501 dialout 25 Feb 10 21:08 access.log.2 -> ../../common/access.log.2
I tried a few things, then looked at the user submitted solutions and one of them was:
ls *[^2]
I did some googling and the man page (and here), but I can't see what this is doing, or how it works.
Can anyone point me to a decent resource so I can read up on it, or tell me how it works?
Let me first quote PesaThes comment to what the command does:
The reference you are looking for is in the manual under: pattern matching. * matches any string, [^2] matches any character that is not 2. So the command lists all files that do not end in 2
Now why this is a solution to the problem is not so clear from your question alone. But if you look what the files contain you will notice that indeed, access.log.2 is the only one that does not contain the string 500 and also the only one whose name ends in 2.
For other sets of files the command ls *[^2] will most probably not output all the files without the string 500 in it, but in this case with those specific files it matches the right files. Another solution would have been for example
echo README; echo access.log; echo access.log.1
that's not an answer to your question, the right way of doing it is
$ grep -sl 500 * .*
-s skip errors (caused by directories); l only filenames; search in * all visible files and .* invisible files.

How to remove an invalidly-named file in Bash? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
Improve this question
I found a file named '.|rst412slp10lad10_noTopo.png', and I really want to remove this. what should I do?
I tried to use ls -al to get the info of the file then I got this:
ls: cannot access '.|rst412slp10lad10_noTopo.png': No such file or directory
total 0
drwxrwxrwx 1 jinshengye jinshengye 4096 Jun 5 17:10 .
drwxrwxrwx 1 jinshengye jinshengye 4096 Jun 5 16:58 ..
-????????? ? ? ? ? ? .|rst412slp10lad10_noTopo.png
What should I do?
Find the inode number(s) with
ls -li
And remove it with
find . -inum 1234 -delete
OK you can try deleting with quotes
rm ".|rst412slp10lad10_noTopo.png"
but that probably won't work, you may need to set rights and /or reboot (or more)... Have a look at this:
https://serverfault.com/questions/65616/question-marks-showing-in-ls-of-directory-io-errors-too?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

database login using shell scripting [closed]

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 5 years ago.
Improve this question
This is the Database entry of my application in server.properties file.
umpdb.driverClassName=org.mariadb.jdbc.Driver
umpdb.url=jdbc:mysql://10.66.11.44:3306/MT_SMS_CHN?useUnicode=true&characterEncoding=UTF-8
umpdb.username=stackuser
umpdb.password=stackpass
I want to print mysql -uuser -ppasswrod -hhostname dbname using linux command.
It means, I need output as below
mysql -ustackuser -pstackpass -h10.66.11.44 MT_SMS_CHN
Please help me for this.
Using awk
awk -F'[:=/?]' '/url/{
h=$6" "$8 # get host and database
}
/username/{
u=$2 # get username
}
/password/{
# print username, password, host and database
printf("mysql -u%s -p%s -h%s\n",u,$2,h);
# we got what we want, exit
# if your file contains more than 1 db config
# just comment below exit keyword
exit
}
' server.conf
Test Results:
$ cat server.conf
umpdb.driverClassName=org.mariadb.jdbc.Driver
umpdb.url=jdbc:mysql://10.66.11.44:3306/MT_SMS_CHN?useUnicode=true&characterEncoding=UTF-8
umpdb.username=stackuser
umpdb.password=stackpass
$ awk -F'[:=/?]' '/url/{h=$6" "$8}/username/{u=$2}/password/{printf("mysql -u%s -p%s -h%s\n",u,$2,h); exit}' server.conf
mysql -ustackuser -pstackpass -h10.66.11.44 MT_SMS_CHN

Resources