[Solved] Calculatin...
 
Notifications
Clear all

[Solved] Calculating the difference between two datetimes?

0 Posts
1 Users
0 Likes
5 Views
0
Topic starter
ManCity10 Asks: Calculating the difference between two datetimes?

Code:
from datetime import datetime
import pytz

cur_time = datetime.now()
cur_time = pytz.utc.localize(cur_time)

rr_name = 'xx_20211005141746.txt'
rr_time =  re.search('_(.*).txt', rr_name).group(1)
rr_time =  datetime.strptime(rr_time, '%Y%m%d%H%M%S')

tzone = "Europe/London"
hb_time = pytz.utc.localize(rr_time).astimezone(pytz.timezone(tzone))
                    
diff = cur_time - hb_time

l_heared = round((diff.total_seconds() / 60), 2)

The difference between cur_time and rr_time is around 6 minutes. Which is 360 seconds How comes delta gives me back 77.65 seconds...

Please note cur_time and rr_name are native datetimes

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.

 

 


 

Unreplied Posts

[Solved] Find and manipulate array element in KSH

Shelby Anne Asks: Find and manipulate array element in KSH
I have an array that reads like this:

Code:
# echo "${ARRAY[@]}"
1=Napp Slice
4=NNN Issue
3=GG Allow
2=CO-OP
1=Quit

And I want to loop through it to see if any contain the word Quit and if so, set that element to a variable. So I ran below:

Code:
for x in ${ARRAY[@]}; do
  if [ $x == *Quit* ]; then
    FOO=$x
    echo $FOO
  else
    break
  fi
done

I want returned to me 1=Quit but when I run it I get:

Code:
# ./myScript.ksh
1=Napp Slice
4=NNN Issue
3=GG Allow
2=CO-OP
1=Quit

How can I pull out just the element containing Quit?

I really tried to see if this question existed before posting, I am newer to shell-scripting. I am sure there is something very simple that I am missing but I can’t seem to get it.

KSH syntax only please as that is all I have available to me.

Thank you!

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.
 
 
 

[Solved] How to use awk to cut text file

Fahrimert Dincer Asks: How to use awk to cut text file
I want to use awk to cut a long text that I found from a website I want. I will save the txt from the part of the text that starts with x*x*x*x to the part that ends with x*x*x*x in a file

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.

 

 


 

[Solved] How can I redirect journalctl output from a systemctl –user service to a file?

Dave Asks: How can I redirect journalctl output from a systemctl –user service to a file?
I need to redirect systemd output (Not the binaries stdout / stderr. I mean the actual systemd output send to journalctl) to a file for a specific user unit.

I know the user can view journalctl with the following

journalctl --follow --user -u userunit.service

However this requires adjusting /etc/systemd/journald.conf, and adjusting storage to Storage=persistent and then reboot. We cannot do this.

I know how to redirect stdout and sterr of the binary to a file. How do I redirect all journalctl output for the unit to a file of my choosing?

Is this possible?

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.

 

 


 

[Solved] What script or process is adjusting my PATH

Pieter Asks: What script or process is adjusting my PATH
I have a pretty basic question, but I can’t find the answer anywhere only. Trust me, I’ve spend the last hour searching for it.

When I start a new terminal the PATH looks like this:

Code:
$ echo $PATH
/home/pieter/.poetry/bin:/home/pieter/.pyenv/plugins/pyenv-virtualenv/shims:/home/pieter/.pyenv/bin:/home/pieter/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/home/pieter/.local/bin:/home/pieter/go/bin:/usr/local/go/bin:/home/pieter/projects/util/bin/:/home/pieter/.npm-packages/bin:/snap/bin

As you can see it starts with a poetry and pyenv directory. But the strange thing is: I can’t find which file adds these to the path.

I’ve checked all the usual suspects. I’ve even moved these files to another directory and the result is the same.

  • ~/.bashrc
  • ~/.profile
  • ~/.zshrc (I’m using zsh by default, but it also happens with bash and sh)
  • ~/.bash_profile (don’t have this one)
  • /etc/bash.bashrc
  • /etc/profile

I’ve checked which scripts start when I open my shell. But there are no files that I can identify.

I’ve searched with ack in my home directory for anything with PATH, but cannot find anything useful.

Even when I uninstall zsh, oh-my-zsh, poetry and pipenv and just use a clean bash shell they are still on the path.

At this point I’m really out of ideas what is modifying my PATH, but I like to know how to control it.

There is one more thing that I think might be useful to share. If I do sudo su pieter, there is no pyenv and poetry on my path.

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.

 

 


 

[Solved] Why isn’t bash logical OR operator working in GNU makefile?

clearlight Asks: Why isn’t bash logical OR operator working in GNU makefile?
I have the following GNU make Makefile


Code:
PWD := $(shell pwd)

obj-m += liason.o

default:
        bash -c '[ "$(lsmod|grep liason)" == "" ] || rmmod liason'
        make -C /src M=$(PWD) modules


I invoke the makefile; it shows this among the output:

Code:
bash -c '[ "" == "" ] ||  rmmod liason'

Thus, rmmod isn’t executed.

However:

Module “liason” is installed.
It even shows up when I execute the following from cmdline.

Code:
$ lsmod|grep liason
liason                 16384  0

Therefore, empty quotes for the same lsmod|grep in the makefile output doesn’t make sense.

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.

 

 


 

[Solved] How do I change whiptail color?

motoTrail Asks: How do I change whiptail color?
I am trying to create a menu with whiptail. And i am looking to change the colors which Whiptail is using.

The working script, which changes the colors, but i do not know how to run commands with this.

Code:
#!/bin/bash

readarray -t newtcols < /etc/newt/palette

newtcols_error=(
root=white,gray
window=white,lightgray
border=black,lightgray
shadow=white,black
button=black,green
actbutton=black,red
compactbutton=black,
title=black,
roottext=black,magenta
textbox=black,lightgray
acttextbox=gray,white
entry=lightgray,gray
disentry=gray,lightgray
checkbox=black,lightgray
actcheckbox=black,green
emptyscale=,black
fullscale=,red
listbox=black,lightgray
actlistbox=lightgray,gray
actsellistbox=black,green
)

NEWT_COLORS="${newtcols[@]} ${newtcols_error[@]}" 
whiptail 
        --backtitle "backtitle"
        --title "title01"
        --menu "title" 0 0 0    
                "hello1" "first option"
                "hello2" "second option"
                "hello3" "third option"
                3>&1 1>&2 2>&3

Here is the non-working script for changing colors in whiptail, but i can run commands with it:

Code:
#!/bin/bash




readarray -t newtcols < /etc/newt/palette

newtcols_error=(
root=white,gray
window=white,lightgray
border=black,lightgray
shadow=white,black
button=black,green
actbutton=black,red
compactbutton=black,
title=black,
roottext=black,magenta
textbox=black,lightgray
acttextbox=gray,white
entry=lightgray,gray
disentry=gray,lightgray
checkbox=black,lightgray
actcheckbox=black,green
emptyscale=,black
fullscale=,red
listbox=black,lightgray
actlistbox=lightgray,gray
actsellistbox=black,green
)

NEWT_COLORS="${newtcols[@]} ${newtcols_error[@]}"


OPTION=$(
whiptail --title "IT ToolBox v0.1" --menu "Choose your option" 15 60 4 
"1" "OPTION 1 - WORKING" 
"2" "hello2" "second option" 
"3" "hello3" "third option"  3>&1 1>&2 2>&3)

exitstatus=$?
if [ $exitstatus = 0 ]; then
    echo "Your chosen option:" $OPTION
else
    echo "You chose Cancel."
fi

case $OPTION in
    1) echo "Working"
            uptime;;
    2) echo "OPTION 2";;
    3) echo "OPTION 3";;
    *) echo "Invalid option.";;
esac

Can someone please help me with ideas, please? Thank you in advance.

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.

 

 


 

[Solved] Bash script escaping quotes

Kalvin Klien Asks: Bash script escaping quotes
I’m writing a bash script to find all the images in the folder and find if they have corrupt endings with ImageMagick.

This is the command I’m trying to automate:

Code:
identify -verbose *.jpg 2>&1 | grep "Corrupt" | egrep -o "([`].*['])"

The issue I’m having is with storing the identify command into a variable.

There are multiple types of quotes that are present in the command I keep getting an error line 8: corrupt: command not found

Code:
#!/bin/bash
# This script will search for all images that are broken and put them into a text file

FILES="*.jpg"

for f in $FILES
do
  corrupt = "identify -verbose "$f" 2>&1 | grep "Corrupt" | egrep -o "([`].*['])""

  if [ -z "$corrupt" ]
  then
    echo $corrupt
  else
    echo  "not corrupt"
  fi
done

Is there a way to escape that command correctly?

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.

 

 


 

[Solved] Error installing on pi400

Anas Kattan Khayta Asks: Error installing on pi400
Im trying to turn my phone webcam into a “fake webcam” for my raspberry pi 400 but i get this error. Anas@raspberrypi:~/Downloads/server/v4l2loopback $ make Building v4l2-loopback driver... make -C /lib/modules/uname -r/build M=/home/Anas/Downloads/server/v4l2loopback modules make[1]: *** /lib/modules/5.10.17-v7l+/build: No such file or directory. Stop. make: *** [Makefile:46: v4l2loopback.ko] Error 2 Anas@raspberrypi:~/Downloads/server/v4l2loopback $ Please help with this.

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.

 

 


 

[Solved] No explicit songs show on my music

user135264 Asks: No explicit songs show on my music
I just purchased a bunch of new songs through the iTunes store on my computer and one by one I saw them being iClouded onto my iPhone.

I was very happy about this until I noticed that none of the songs that i bought marked “Explicit” were showing up.

Is there a way to fix this because I like these songs and honestly it’s like one word so I don’t see the big deal.

Can someone please tell me if it is possible to get these explicit songs onto music on my phone?

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.

 

 


 

[Solved] Daisy chain Dell with DisplayPort (output) to Apple Thunderbolt Display

Demiurg Asks: Daisy chain Dell with DisplayPort (output) to Apple Thunderbolt Display
I have a Dell P2720DC and Apple Thunderbolt Displays I want to daisy chain. Since the Dell has USB-C PD, I prefer connecting my MacBook to it, but then I’m not sure I can connect its DisplayPort output to Apple Thunderbolt Display.

Would it work? Which cable/adaptor to use?

If not, are there other options?

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.

 

 


 

Share: