quinta-feira, 28 de outubro de 2021

Comandos interessantes do linux

look 

Look é um utilitário que faz parte do pacote bsdmainutils. Ele serve para procurar linhas que começam com determinada expressão dentro de um arquivo. Se nenhum arquivo for especificado, ele faz a consulta em /usr/share/dict/words. 


ex: 

$ look hello 


espaço

utilizar um espaço no começo de qualquer comando faz ele não ficar registrado no history

ex: 

$ ls /home


cal e ncal

mosta o calendario

ex: 

$ cal janeiro 2021

$ ncal janeiro 2021

 

CTRL + x + e

abre um editor de texto e ao salvar executa comando

 

yes 

é um loop muito util para aceitar

ex: 

$ yes | apt-get install nano

OBS: você pode alterar para outra palavra 

ex: 

$ yes no

$ yes teste

 

servidor de web rapido com python

ex: 

vá até o diretório aonde está a pagina html e rode o comando

$ python3 -m http.server

 

factor 

mostra o numero fatorial 

ex:

$ factor 22

quinta-feira, 21 de outubro de 2021

enviar email pelo terminal / curl

instale o curl

# apt-get install curl

 

crie um arquivo com o nome mail.txt

$ touch mail.txt

edite o arquivo 

$ vim mail.txt

From: "User Name" <username@gmail.com>
To: "John Smith" <john@example.com>
Subject: This is a test

Hi John,
I’m sending this mail with curl thru my gmail account.
Bye!

autorize o google a utilizar o curl

site 1: https://www.google.com/settings/security/lesssecureapps

site 2: https://accounts.google.com/DisplayUnlockCaptcha

configure a linha de comando abaixo conforme seu email

$ curl --ssl-reqd \
  --url 'smtps://smtp.gmail.com:465' \
  --user 'username@gmail.com:password' \
  --mail-from 'username@gmail.com' \
  --mail-rcpt 'john@example.com' \
  --upload-file 'mail.txt'

 

enviar email pelo terminal / mutt

 Instale o mutt

# apt-get install mutt

configure o muttrc em /home/USER/.config/mutt obs: caso o diretório não exista crie!

criar diretorio

$ mkdir /home/USER/.config/mutt

crie o arquivo muttrc no diretório 

$ touch /home/USER/.config/mutt/muttrc

configure o arquivo

$ vim /home/USER/.config/mutt/muttrc

# MailBox em $HOME.
set mbox_type=maildir  
set mbox="~/mail/inbox/"  
set spoolfile="~/mail/inbox/"  
set folder="~/mail/"  
set record="~/mail/sent/"  
set postponed="~/mail/postponed/"  

# Conta Gmail.
set from = "SEU_LOGIN@gmail.com"  
set realname = "SEU_NOME"  
set imap_user = "SEU_LOGIN@gmail.com"  
set imap_pass = "SUA_SENHA"  

# Editor padrão.  
set editor=nano  

# Pastas IMAP.
set folder = "imaps://imap.gmail.com:993"  
set spoolfile = "+INBOX"  
set postponed ="+[Gmail]/Drafts"  

# Pastas Locais.
set header_cache =~/.mutt/cache/headers  
set message_cachedir =~/.mutt/cache/bodies  
set certificate_file =~/.mutt/certificates  

# SMTP Config.
set smtp_url = "smtp://SEU_LOGIN@smtp.gmail.com:587/"  
set smtp_pass = "SUA_SENHA"  

# Special Keybindings.  
bind editor <space> noop  
macro index gi "<change-folder>=INBOX<enter>" "Go to inbox"  
macro index ga "<change-folder>=[Gmail]/All Mail<enter>" "Go to all mail"  
macro index gs "<change-folder>=[Gmail]/Sent Mail<enter>" "Go to Sent Mail"  
macro index gd "<change-folder>=[Gmail]/Drafts<enter>" "Go to drafts"  

# Mutt Session Security.
set move = no
set imap_keepalive = 900  

# Cores. 
color hdrdefault cyan default  
color attachment yellow default  
color header brightyellow default "From: "  
color header brightyellow default "Subject: "  
color header brightyellow default "Date: "  
color quoted green default  
color quoted1 cyan default  
color quoted2 green default  
color quoted3 cyan default  
color error   red       default
color message  white      default
color indicator white      red
color status  white      blue
color tree   red       default
color search  white      blue
color markers  red       default
color index   yellow default '~O'  
color index   yellow default '~N'  
color index   brightred    default '~F'
color index   blue default  '~D'

# Cores.

# emails.
color body  brightred black [\-\.+_a-zA-Z0-9]+@[\-\.a-zA-Z0-9]+

# URLs.
color body  brightblue black (https?|ftp)://[\-\.,/%~_:?&=\#a-zA-Z0-9]+

 

autorize o google a utilizar o mutt

site 1: https://www.google.com/settings/security/lesssecureapps

site 2: https://accounts.google.com/DisplayUnlockCaptcha

 

para enviar um email 

$ echo 'texto' | mutt -s 'assunto do e-mail' email@dominio.com

 

Enviar e-mail pelo terminal / ssmtp

 instale o ssmtp

# apt-get install ssmtp

configure o ssmtp.conf em /etc/ssmtp/ssmtp.conf

$ vim /etc/ssmtp/ssmtp.conf

adicione as linhas abaixo

root=USER@gmail.com
mailhub=smtp.gmail.com:465
FromLineOverride=YES
AuthUser=USER@gmail.com
AuthPass=PASSWORD
UseTLS=YES

autorize o google a utilizar o ssmtp

site 1: https://www.google.com/settings/security/lesssecureapps

site 2: https://accounts.google.com/DisplayUnlockCaptcha

para enviar um e-mail

$ ssmtp -v email@dominio.com < arquivo.txt

ou

$ echo "texto" | ssmtp -v email@dominio.com

To-Do List - lista de tarefas em shell script

adicione a linha abaixo no .bashrc

# To-Do List 

export TODO="${HOME}/Documentos/todo.txt"
 

tla() { [ $# -eq 0 ] && cat $TODO || echo "$(echo $* | md5sum | cut -c 1-5) →  $*" >> $TODO ;}
 

tlr() { [ $# -z ] 2>/dev/null && read -n1 -p "press ENTER to delete all tasks or CTRL+C to cancel" ; sed -i "/^$*/d" $TODO ;}

salve o arquivo e rode o comando 

$ source .bashrc

para adicionar uma tarefa 

$ tla 'texto'

para remover

$ tlr 'id'

 para remover todas as tarefas

$ tlr

outra opção com numeração das linhas utilizando o nl 

# To-Do List
export TODO="${HOME}/Documentos/todo.txt"

tla(){
if [ $# -eq 0 ]; then
echo "$(sed -i 's/^ *[0-9]\+.//g' $TODO ; nl -s " " $TODO )" > $TODO ; sed -i 's/^[ \t]*//' $TODO
cat $TODO
else
sed -i '/^[[:space:]]*$/d' $TODO ; echo "→  $*" >> $TODO ; echo "$(sed -i 's/^ *[0-9]\+.//g' $TODO ; nl -s " " $TODO )" > $TODO ; sed -i 's/^[ \t]*//' $TODO
fi
}

tlr() { [ $# -eq 0 ] 2>/dev/null && read -n1 -p "press ENTER to delete all tasks or CTRL+C to cancel" ; sed -i "/^$*/d" $TODO ;}

alternativa

caso não queira utilizar o md5sum ou nl para gerar o id utilize

tla() { [ $# -eq 0 ] && cat $TODO || echo "$(echo $* | cat /dev/urandom | tr -dc '0-9a-zA-Z' | fold -w 5 | head -n 1) →  $*" >> $TODO ;}

OBS: caso queira enviar a lista de afazeres para um e-mail fiz essa alternativa

adicione as linhas abaixo no .bashrc

export TODO_BACKUP="${HOME}/Documentos/todo_backup.txt"

tlb() { read -sp "Enter your Google App password : " password ; echo 'From: "username" <email@gmail.com>' >> "${TODO_BACKUP}" ; echo 'To: "user" <email@receiver.com>' >> "${TODO_BACKUP}" ; echo 'Subject: To-Do List' >> "${TODO_BACKUP}" ; echo >> "${TODO_BACKUP}" ; cat "${TODO}" >> "${TODO_BACKUP}" ; echo "" >> "${TODO_BACKUP}" ; curl --ssl-reqd --url 'smtps://smtp.gmail.com:465' --user 'username@gmail.com:'"${password}"'' --mail-from 'username@gmail.com' --mail-rcpt 'email@receiver.com' --upload-file ''"${TODO_BACKUP}"'' ; rm -r "${TODO_BACKUP}" ; unset password ;}

após configurar a função tlb com seu email de envio e recebimento, execute o comando

$ source .bashrc

OBS: lembrando que não é necessário configurar o password, justamente por isso coloquei o read para pegar ele e o unset para resetar a variável  

lembrando que é necessario autorizar o google a utilizar o curl 

site 1: https://www.google.com/settings/security/lesssecureapps

site 2: https://accounts.google.com/DisplayUnlockCaptcha

após configurar, para enviar a lista para email é simples

$ tlb 


OBS 2: 

o comando tlr deleta os arquivos se o usuario apertar qualquer tecla, para resolver isso use o tlr abaixo

tlr(){                                                                                                                         read -p "Yes to delete all tasks No to cancel: " answer                                                                        
case ${answer:0:1} in                                                                                                          
    y|Y )                                                                                                                      
        sed -i "/^$*/d" $TODO                                                                                                  
    ;;                                                                                                                         
    * )                                                                                                                        
        echo                                                                                                                   
    ;;                                                                                                                         
esac                                                                                                                           
}

quarta-feira, 6 de outubro de 2021

Ver preço do bitcoin via terminal

1

$ watch -tcn5  "curl -s https://api-pub.bitfinex.com/v2/ticker/tBTCUSD | awk -F',' '{print \"BTC/USD: $\" \$7}'"

 

2

$ curl -s http://api.coindesk.com/v1/bpi/currentprice.json | python -c "import json, sys; print(json.load(sys.stdin)['bpi']['USD']['rate'])" 

 

3

$ telnet ticker.bitcointicker.co 10080

 

4

$ echo "1 BTC = $(curl -s https://api.binance.com/api/v1/ticker/price?symbol=BTCUSDT | jq .price | xargs)"

 ou

$ echo "1 BTC = $(curl -s 'https://api.binance.com/api/v1/ticker/price?symbol=BTCUSDT' | cut -d: -f3 | sed 's/"//g; s/}//g') USD"


5

https://github.com/bichenkk/coinmon

 

6

Script

#!/bin/bash

# Prices are in USD, EUR & GBP (in real time)
# curl must be installed in terminal
clear
echo "Coindesk BTC: "
echo "USD-----------------EUR-----------------GBP"

while [ 1 ]
do
curl -s http://api.coindesk.com/v1/bpi/currentprice.json | python -c "import json, sys; bitcoin=json.load(sys.stdin); print bitcoin['bpi']['USD']['rate'] + '\t' + bitcoin['bpi']['EUR']['rate'] + '\t' + bitcoin['bpi']['GBP']['rate']"
printf "\033[A"
sleep 5
done

terça-feira, 5 de outubro de 2021

Converter html para pdf

link para Download do programa: https://wkhtmltopdf.org/

 

Instalação: 

# dpkg -i wkhtmltox_0.12.6-1.focal_amd64.deb

 OBS: talvez você tenha que rodar

# apt-get -f install


Como usar:

 wkhtmltopdf www.linkdosite.com output.pdf


Alternativas

weasyprint

instalar:

# apt-get install weasyprint

 

Como usar:

weasyprint file.html output.pdf


Alternativa online

https://html2pdf.com/

sábado, 2 de outubro de 2021

Desabilitar pedido de senha ao abrir e fechar tampa notebook ubuntu 20.04

desabilitar

$ gsettings set org.gnome.desktop.lockdown disable-lock-screen 'true'

 

habilitar

 $ gsettings set org.gnome.desktop.lockdown disable-lock-screen 'false'