Posts

Showing posts from July, 2017

echo $VAR1 | bash / echo `la -lart`

[root@localhost java]# VAR1="ls -lart" [root@localhost java]# echo $VAR1 ls -lart [root@localhost java]# echo "$VAR1" ls -lart [root@localhost java]# echo $VAR1 | bash total 64 drwxr-xr-x. 3 root root    18 Jul 30 14:49 .. drwxr-xr-x. 2 root root   123 Jul 30 14:49 files drwxr-xr-x. 3 root root    19 Jul 30 14:50 java drwxr-xr-x. 4 root root    41 Jul 30 15:02 . -rw-r--r--. 1 root root 63394 Jul 30 15:02 ff [root@localhost java]# echo `ls -lart` total 64 drwxr-xr-x. 3 root root 18 Jul 30 14:49 .. drwxr-xr-x. 2 root root 123 Jul 30 14:49 files drwxr-xr-x. 3 root root 19 Jul 30 14:50 java drwxr-xr-x. 4 root root 41 Jul 30 15:02 . -rw-r--r--. 1 root root 63394 Jul 30 15:02 ff

sed -n '10-11'p filename | less -N -n G | less +100 -N file

[root@localhost java]# sed -n '99,100'p ff gshadow- gss less -N / -n show/hide number lines less + 12345 - N / var / log / hugelogfile This will open a file displaying the line numbers and starting at line 12345 g and the line number to go forward G and the line number to go backwards G goes to the bottom of the file

tac filename | less

 if you actually want/need to read a file backwards (last line first): tac filename | less

vimdiff rsync -rvnc

vimdiff  /path/to/file scp://username@remotehost//path/to/file If you just want to see what files are different, rather than a diff of the actual files, then you can use  rsync --dry-run You can use  rsync  in dry run mode, as suggested briefly in  another answer . It lists any files that are different. For that, use the  rvnc  options ( r =recursive,  v =verbose,  n = dry-run,  c =checksum). With  rsync  in pull mode ( rsync [OPTION...] [USER@]HOST:SRC... [DEST] ), an example is: rsync -rvnc root@182.18.158.207:/var/www/html/dev/ .

Why crontab scripts are not working? Different environment

Cron passes a minimal set of environment variables to your jobs. To see the difference, add a dummy job like this: * * * * * env > /tmp/env.output Wait for  /tmp/env.output  to be created, then remove the job again. Now compare the contents of  /tmp/env.output  with the output of  env  run in your regular terminal. A common "gotcha" here is the  PATH  environment variable being different. Maybe your cron script uses the command  somecommand  found in  /opt/someApp/bin , which you've added to  PATH  in  /etc/environment ? cron ignores  PATH  from that file, so runnning  somecommand  from your script will fail when run with cron, but work when run in a terminal. It's worth noting that variables from  /etc/environment  will be passed on to cron jobs, just not the variables cron specifically sets itself, such as  PATH . To get around that, just set your own  PATH  ...

find . -iname file | find /path/to/base/dir -type d -exec chmod 755 {} +

ubu1404@ubuntu1404lb01:/tmp$ find . -iname file find: `./vmware-root': Permission denied ./file ./FILE To recursively give  directories  read&execute privileges: find /path/to/base/dir -type d -exec chmod 755 {} + To recursively give  files  read privileges: find /path/to/base/dir -type f -exec chmod 644 {} +

ypcat - prints the values of all keys from the NIS database

ypcat  prints the values of all keys from the NIS database specified by  mapname,  which may be a map name or a map nickname.   ypcat passwd | grep username ypcat -k netgroup.byuser | grep username

15 managing disk - creating encrypted partition partprobe

Image
[root@svn ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.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/sdb: 5368 MB, 5368709120 bytes, 10485760 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0xf12de6be    Device Boot      Start         End      Blocks   Id  System /dev/sdb1            2048       206847       102400   83  Linux Command (m for help): #sectors  10485760   and  206847   means there is free capacity Command (m for help): n Partition type:    p   primary (1 primary, 0 extended, 3 free)    e   extended Select (default...

15 managing disk - understanding encrypted LUKS partitions / dmsetup status / swapon -s

Image
1. on device level you use fdisk to create a partition 2. once you created a partition, you use cryptsetup luksFormat\  to create encryption layer 3. after creation of encryption layer, you need to open a device cryptsetup luksOpen\  3.1. it creates a devices /dev/mapper/secret and brings to luks level 4. mkfs should be done on /dev/mapper/secretedevicename instead of on /dev/sdb1 5. mount /dev/mapper/secret and put your files there check if there are any encrypted LUKS partitions [root@svn ~]# blkid /dev/sda1: UUID="6e3708b2-09ea-43f3-b0f0-9b43a157b3b1" TYPE="xfs"  /dev/sda2: UUID="98h644-2gqM-2SsL-q0lA-qUEE-Ivz8-TUZULc" TYPE="LVM2_member"  /dev/sdb1: LABEL="myfs" UUID="05dbcff3-e639-40cb-bbe7-0da595186f1a" TYPE="xfs"  /dev/sr0: UUID="2016-12-05-13-52-39-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"  /dev/mapper/cl-root: UUID="da05cdf9-1418-4e...

vim root permission :w !sudo tee %

/etc  consists of all configurations files so to edit the files under  /etc  you need the superuser permissions but sometime we forget to use  sudo . but at that time we can also use :w !sudo tee % then enter your administrator password :q! to exit successfully

15 managing disk - understanding /etc/fstab xfs_admin mount -o rw,remount /

the classical way to mount filelsystems automatically is to use fstab there is another method which is based on systemd [root@svn ~]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Wed Apr 26 17:25:59 2017 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/cl-root     /                       xfs     defaults        0 0 UUID=6e3708b2-09ea-43f3-b0f0-9b43a157b3b1 /boot                   xfs     defaults        0 0 /dev/mapper/cl-swap     swap                    swap    defaults        0 0 [root@svn ~]#  #description /boot - where you want to mount filesystem xfs - filesystem defaults ...