No exemplo a seguir:
$ ip a | grep scope.global
inet 147.202.85.48/24 brd 147.202.85.255 scope global dynamic enp0s3
O que significa o 'brd'?
No exemplo a seguir:
$ ip a | grep scope.global
inet 147.202.85.48/24 brd 147.202.85.255 scope global dynamic enp0s3
O que significa o 'brd'?
Eu tenho um arquivo cujo conteúdo é semelhante ao seguinte.
0
0
0.2
0
0
0
0
Eu preciso remover todas as linhas com um único zero.
Eu estava pensando em usar grep -v "0"
, mas isso remove também a linha contendo 0.2. Eu vi que poderia usar a -w
opção, mas isso também não parece funcionar.
Como posso remover todas as linhas contendo apenas um único 0 e manter todas essas linhas começando com 0?
read -p "Enter yes/no " SOMEVAR
SOMEVAR=`"echo ${SOMEVAR,,}"`
O código acima me dá um ${SOMEVAR,,}: bad substitution
erro.
Neste momento tenho o seguinte:
# this function is meant for future script expansions
# its purpose is clear, i.e. to clean up some temp files
# now, it is doing nothing, just a special null command
cleanup_on_signal() { :; }
# define functions to handle signals
# treat them as errors with appropriate messages
# example calls:
# kill -15 this_script_name # POSIX, all shells compatible
# kill -TERM this_script_name # Bash and alike - newer shells
signal_handler_HUP() { cleanup_on_signal; print_error_and_exit "\\ntrap()" "Caught SIGHUP (1).\\n\\tClean-up finished.\\n\\tTerminating. Bye!"; }
signal_handler_INT() { cleanup_on_signal; print_error_and_exit "\\ntrap()" "Caught SIGINT (2).\\n\\tClean-up finished.\\n\\tTerminating. Bye!"; }
signal_handler_QUIT() { cleanup_on_signal; print_error_and_exit "\\ntrap()" "Caught SIGQUIT (3).\\n\\tClean-up finished.\\n\\tTerminating. Bye!"; }
signal_handler_ABRT() { cleanup_on_signal; print_error_and_exit "\\ntrap()" "Caught SIGABRT (6).\\n\\tClean-up finished.\\n\\tTerminating. Bye!"; }
signal_handler_TERM() { cleanup_on_signal; print_error_and_exit "\\ntrap()" "Caught SIGTERM (15).\\n\\tClean-up finished.\\n\\tTerminating. Bye!"; }
# use the above functions as signal handlers;
# note that the SIG* constants are undefined in POSIX,
# and numbers are to be used for the signals instead
trap 'signal_handler_HUP' 1; trap 'signal_handler_INT' 2; trap 'signal_handler_QUIT' 3; trap 'signal_handler_ABRT' 6; trap 'signal_handler_TERM' 15
Eu quero que o script termine ordenadamente no desligamento, o que agora acontece.
Mas abri uma sugestão de um colega para fazer uma pergunta no CTRL+C ao invés de sair do shell.
Não quero desligar a máquina, não faço isso com frequência, de qualquer forma:
Que sinal é enviado para programas/scripts em execução no desligamento?
Perdi algumas horas tentando executar o servidor VNC (x0vncserver) e o cliente se recusou a se conectar com uma mensagem estranha que
No password configured for VNC Auth
O servidor também imprime este erro
SVncAuth: opening password file '~/.vnc/passwd' failed
Ok, perdi muito tempo até perceber que o til não era expandido pelo shell, nem pelo x0vncserver. Então eu fiz esses testes
$ echo --PasswordFile=~/.vnc/passwd
--PasswordFile=~/.vnc/passwd
Mas
$ echo PasswordFile=~/.vnc/passwd
PasswordFile=/home/tichomir/.vnc/passwd
Por que é que? Por que o shell se recusa a expandir o til se o argumento começa com um traço? Eu pensei que o til sempre se expandiria desde que não fosse citado, mas aparentemente há outra regra que entra em jogo?
Passei a maior parte do mês tentando instalar, reinstalar, excluir manualmente e reinstalar o último linux-image-4.9.0-8 (ou dele) no meu Debian 9 (Stretch), mas ele sempre (re) inicializa nessa versão errada do Linux 3.16.0-5.
Eu até deletei todo o /boot
conteúdo do diretório e reinstalei.
Eu tenho uma instalação padrão do Debian 9 na /dev/sda
unidade onde /dev/sda1
está a /boot
partição autônoma.
Minha lista de verificação:
/etc/kernel-img.conf
apt
em vez deapt-get
Esse é um sistema de quebra-cabeça aqui que eu mesmo encontrei.
O diretório mais recente de /boot
é:
$ ls -lat /boot
total 106000
drwxr-xr-x 23 root root 4096 Jan 17 12:25 ..
drwxr-xr-x 2 root root 4096 Jan 17 12:17 grub
drwxr-xr-x 3 root root 4096 Jan 17 12:17 .
-rw-r--r-- 1 root root 19595458 Jan 17 12:17 initrd.img-4.9.0-8-amd64
-rw-r--r-- 1 root root 19446192 Jan 17 12:08 initrd.img-4.9.0-5-amd64
-rw-r--r-- 1 root root 19587298 Nov 7 13:58 initrd.img-4.9.0-7-amd64
-rw-r--r-- 1 root root 186563 Oct 27 14:46 config-4.9.0-8-amd64
-rw-r--r-- 1 root root 3195896 Oct 27 14:46 System.map-4.9.0-8-amd64
-rw-r--r-- 1 root root 4232992 Oct 27 14:46 vmlinuz-4.9.0-8-amd64
-rw-r--r-- 1 root root 186568 Aug 13 15:31 config-4.9.0-7-amd64
-rw-r--r-- 1 root root 3192069 Aug 13 15:31 System.map-4.9.0-7-amd64
-rw-r--r-- 1 root root 4232992 Aug 13 15:31 vmlinuz-4.9.0-7-amd64
-rw-r--r-- 1 root root 19478453 Feb 19 2018 initrd.img-4.9.0-3-amd64
-rw-r--r-- 1 root root 186473 Jan 4 2018 config-4.9.0-5-amd64
-rw-r--r-- 1 root root 3185098 Jan 4 2018 System.map-4.9.0-5-amd64
-rw-r--r-- 1 root root 4216608 Jan 4 2018 vmlinuz-4.9.0-5-amd64
-rw-r--r-- 1 root root 186386 Sep 18 2017 config-4.9.0-3-amd64
-rw-r--r-- 1 root root 3180929 Sep 18 2017 System.map-4.9.0-3-amd64
-rw-r--r-- 1 root root 4204320 Sep 18 2017 vmlinuz-4.9.0-3-amd64
Percebi que não há imagem/initramfs do Linux 3.16.0-5.
No entanto, a execução uname
sempre resulta em:
Linux arca 3.16.0-5-amd64 #1 SMP Debian 3.16.51-3+deb8u1 (2018-01-08)
O conteúdo do diretório de nível superior e seus links simbólicos também estão corretos:
# ls -lat /
total 112
drwxrwxrwt 14 root root 11264 Jan 17 13:15 tmp
drwxr-xr-x 33 root root 1080 Jan 17 12:46 run
drwxr-xr-x 19 root root 3480 Jan 17 12:45 dev
drwxr-xr-x 178 root root 12288 Jan 17 12:45 etc
dr-xr-xr-x 13 root root 0 Jan 17 12:44 sys
dr-xr-xr-x 195 root root 0 Jan 17 12:44 proc
drwx------ 36 root root 4096 Jan 17 12:44 root
drwxr-xr-x 23 root root 4096 Jan 17 12:25 .
drwxr-xr-x 23 root root 4096 Jan 17 12:25 ..
drwxr-xr-x 3 root root 4096 Jan 17 12:17 boot
drwxr-xr-x 2 root root 12288 Jan 17 11:27 sbin
drwxrwxr-x 2 root root 4096 Jan 17 11:27 bin
lrwxrwxrwx 1 root root 29 Nov 7 13:56 initrd.img -> boot/initrd.img-4.9.0-8-amd64
lrwxrwxrwx 1 root root 29 Nov 7 13:56 initrd.img.crap -> boot/initrd.img-4.9.0-7-amd64
lrwxrwxrwx 1 root root 26 Nov 7 13:56 vmlinuz -> boot/vmlinuz-4.9.0-8-amd64
lrwxrwxrwx 1 root root 26 Nov 7 13:56 vmlinuz.crap.4.9.0.7 -> boot/vmlinuz-4.9.0-7-amd64
drwxr-xr-x 6 root root 4096 Oct 11 17:01 opt
drwxr-xr-x 20 root root 4096 Oct 10 16:52 lib
drwxr-xr-x 3 root root 4096 Oct 10 16:34 srv
drwxr-xr-x 8 root root 4096 Sep 5 13:34 home
drwxr-xr-x 13 root root 4096 Mar 17 2018 var
drwxr-xr-x 2 root root 4096 Mar 17 2018 lib64
drwxr-xr-x 7 root root 4096 Feb 19 2018 media
drwxr-xr-x 2 root root 4096 Feb 19 2018 debootstrap
drwxr-xr-x 10 root root 4096 May 16 2017 usr
drwxr-xr-x 2 root root 4096 Oct 8 2016 mnt
drwx------ 2 root root 16384 Oct 8 2016 lost+found
Mesmo a partição de inicialização sda1
para /boot
está marcada corretamente.
# fdisk /dev/sda
Welcome to fdisk (util-linux 2.29.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): p
Disk /dev/sda: 931.5 GiB, 1000204886016 bytes, 1953525168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xfa4b1728
Device Boot Start End Sectors Size Id Type
/dev/sda1 * 2048 499711 497664 243M 83 Linux
/dev/sda2 501758 1953523711 1953021954 931.3G 5 Extended
/dev/sda5 501760 1953523711 1953021952 931.3G 8e Linux LVM
Partition 2 does not start on physical sector boundary.
Command (m for help): quit
Eu quero usar um comando sobre ssh:
ssh myuser@myhost mycommand
mas fazendo isso eu sempre recebo:
sh: mycommand: command not found
usando o seguinte obviamente funciona:
ssh myuser@myhost /usr/local/bin/mycommand
e eu entendo o porquê: é porque o comando é de alguma forma executado em um shell sem login.
Usar o comando completo ou qualquer outro parâmetro no meu comando ssh não é uma opção no meu cenário. Meu comando é executado por um script que não posso tocar e funcionou em todos os hosts, exceto este.
O host que está me dando o problema é um Synology NAS e a configuração /etc/passwd para esse myuser é:
myuser:x:1048:100::/var/services/homes/myuser:/bin/sh
Novamente:
Eu posso:
Não posso deixar de querer:
Alguém pode explicar em detalhes o que está acontecendo com o seguinte. Vamos imaginar que estou montando um diretório com noexec
opção da seguinte forma:
mount -o noexec /dev/mapper/fedora-data /data
Então, para verificar isso, executei mount | grep data
:
/dev/mapper/fedora-data on /data type ext4 (rw,noexec,relatime,seclabel,data=ordered)
Agora dentro /data
estou criando um script simples chamado hello_world
da seguinte forma:
#!/bin/bash
echo "Hello World"
whoami
Então eu fiz o script executável por chmod u+x hello_world
(isso, no entanto, não terá efeito em um sistema de arquivos com noexec
opções) e tentei executá-lo:
# ./hello_world
-bash: ./hello_world: Permission denied
No entanto, pré-pender bash
para o arquivo resulta em:
# bash hello_world
Hello World
root
Então criei um simples hello_world.c
com o seguinte conteúdo:
#include <stdio.h>
int main()
{
printf("Hello World\n");
return 0;
}
Compilei usando cc -o hello_world hello_world.c
Agora rodando:
# ./hello_world
-bash: ./hello_world: Permission denied
Então eu tentei executá-lo usando
/lib64/ld-linux-x86-64.so.2 hello_world
O erro:
./hello_world: error while loading shared libraries: ./hello_world: failed to map segment from shared object: Operation not permitted
Portanto, é claro que isso é verdade, pois ldd
retorna o seguinte:
ldd hello_world
ldd: warning: you do not have execution permission for `./hello_world'
not a dynamic executable
Em outro sistema em que noexec
a opção de montagem não se aplica, vejo:
ldd hello_world
linux-vdso.so.1 (0x00007ffc1c127000)
libc.so.6 => /lib64/libc.so.6 (0x00007facd9d5a000)
/lib64/ld-linux-x86-64.so.2 (0x00007facd9f3e000)
Agora minha pergunta é esta: Por que a execução de um script bash em um sistema de arquivos com noexec
opção funciona, mas não um c
programa compilado? O que está acontecendo sob o capô?
Eu descobri recentemente um exploit, onde eu (ou supondo que alguém) pode recriptografar meu arquivo zip criptografado sem precisar saber a senha:
#zip --encrypt encrypted.zip -r dir1/
O acima solicitará que o usuário insira uma nova senha. Está faltando alguma coisa ou isso é um problema conhecido?