Wednesday, 17 May 2023

How to listen or telnet between 2 ubuntu PCs, to verify firewall in ubuntu pc?

one way is to use telnet in a ubuntu pc

telnet <IP address> <Port>

telnet 44.55.66.77 9090


another way is to use nc for listening to a port

in the host pc: nc -l 9090

in the remote pc: nc 44.55.66.77 9090

then, type anything on remote pc, you should see it in host pc


If you want to check it from windows, open PowerShell:-

Test-NetConnection -ComputerName host -Port port

Test-NetConnection -ComputerName 192.168.0.1 -Port 80

Tuesday, 9 May 2023

How to share internet between ubuntu pc using a usb wifi dongle?

pcA: ubuntu with usb dongle, with internet

pcB: ubuntu without usb dongle, no internet


step1: check the IP address of pcA if change the IPv4 Method to "Shared to other computers". Prior to this, pcA should have a default IP address and we named it as pcAip1.

Please take note that do not change any setting on "USB Ethernet" because it is an internet connection.

You should change the setting only on "PCI Ethernet".

Open setting of "PCI Ethernet", select IPv4, select "Shared to other computers" under IPv4 Method.

Once it is done, just click Apply.

Then, open terminal and type "nmcli dev show eth0" where eth0 is the network interface name of "PCI Ethernet", sometime it is named as "enp8s0", "enp3s0", etc.

You should get IP address of pcA under "Shared to other computers" condition and we named it as pcAip2:-

IP4.ADDRESS[1]:                         10.42.0.1/24

You will see a different IP address if you change the "Shared to other computers" to Automatic or Manual, which is pcAip1. Write down the pcAip2.

Change it back to manual IP addresss so that you can connect to pcB using original IP.


step2: ssh and login to pcB using default IP address or pcBip1, type "sudo nmtui", edit connection of wired connection

change the setting from before to after as following:-

before, we have pcBip1: 10.201.56.19


after, we have pcBip2: 10.42.0.2


where you should define a temporary IP address of pcB which is 10.42.0.2/24, Gateway you should put pcAip2 which is 10.42.0.1 without 24, DNS servers also the same.

Once it is done, you can reboot pcB.

step3: now from pcA, change again the IPv4 method from manual to "Shared to other computers".

Open terminal, you can try to ssh login pcB using pcBip2 address. Once you login, you can try to ping www.google.com. If you able to receive a reply from Google, then congrats. If not, something wrong with your setting, try again.


step4: now in pcB, you have done your business with internet connection, you want to switch it back to original setting which is from pcBip2 to pcBip1. You can just reverse the setting in step2. Then, you can reboot pcB.


step5: back to pcA, you can restore the PCI Ethernet setting back to pcAip1. You should able to connect pcBip1 as usual, but pcB should not have any internet now

Monday, 1 May 2023

How to check pytorch installation error?

import torch

torch.backends.cuda.matmul.allow_tf32 = True

torch.backends.cudnn.benchmark = True

torch.backends.cudnn.deterministic = False

torch.backends.cudnn.allow_tf32 = True

data = torch.randn([1, 512, 120, 67], dtype=torch.float, device='cuda', requires_grad=True)

net = torch.nn.Conv2d(512, 512, kernel_size=[3, 3], padding=[1, 1], stride=[1, 1], dilation=[1, 1], groups=1)

net = net.cuda().float()

out = net(data)

out.backward(torch.randn_like(out))

torch.cuda.synchronize()


Tuesday, 28 March 2023

How to resolve the following c++ compilation error?

CUDA error: no kernel image is available for execution on the device

> check the cuda architecture version used in opencv CMakeLists.txt, 30 series should 8.6, 20 series should be 7.5


CMake Error: The following variables are used in this project, but they are set to NOTFOUND.

Please set them or make sure they are set and tested correctly in the CMake files:

CUDA_cublas_device_LIBRARY (ADVANCED)

   linked by target "caffe" in directory /home/jakebmalis/Documents/openpose/3rdparty/caffe/src/caffe

> check the cmake version, suggest to use 3.21, search how to install cmake 

Sunday, 26 March 2023

How to install and update libreoffice templates?

 https://github.com/dohliam/libreoffice-impress-templates/wiki/Ubuntu-Debian-Install-Guide

Monday, 13 March 2023

How to backup journald daily?

 #!/bin/bash


# Set the backup directory

BACKUP_DIR=/logs


# Create the backup directory if it doesn't exist

mkdir -p $BACKUP_DIR


# Get the current date in the format "YYYY-MM-DD"

DATE=$(date +%Y-%m-%d)

PREV_DATE=$(date -u -d "1 day ago 00:00:01" +"%Y-%m-%d %H:%M:%S")


# Loop through all running containers and backup their logs

for container in $(docker ps --format '{{.Names}}'); do

  journalctl -b CONTAINER_NAME=$container --since "$PREV_DATE" >> $BACKUP_DIR/$container-$DATE.log

done


---

You also need to set the /etc/docker/daemon and restart the docker

{
    "default-runtime": "nvidia",
    "runtimes": {
        "nvidia": {
            "path": "nvidia-container-runtime",
            "runtimeArgs": []
        }
    },
    "log-driver": "journald"
}

Friday, 10 February 2023

How to use Python with Telegram bot?

 step1: create a new bot with Telegram botfather

/newbot

test_bot

test_bot

(get the telegram bot token, <telegramBotToken>)


step2: check the new bot chat id, type the following url in the browser, https://api.telegram.org/bot<telegramBotToken>/getUpdates?offset=0

send a message to the new bot in telegram

refresh the browser to get the chat id

(get the telegram bot chat id, <telegramChatID>)


step3: add the bot into a new group and send a message in the group. Then, refresh step2 above

you will see the group chat id, copy and paste into your Python code

 

step4: use a Python code to verify Telegram bot

import requests

TOKEN = "<telegramBotToken>"

chat_id = "<telegramChatID>"

message = "hello from your telegram bot"

url = f"https://api.telegram.org/bot{TOKEN}/sendMessage?chat_id={chat_id}&text={message}"

print(requests.get(url).json()) # this sends the message