Differences between revisions 46 and 74 (spanning 28 versions)
Revision 46 as of 2017-09-02 07:06:03
Size: 15017
Editor: localhost
Comment:
Revision 74 as of 2021-11-12 15:14:40
Size: 24398
Editor: merlyn
Comment:
Deletions are marked like this. Additions are marked like this.
Line 6: Line 6:
= Diff, show modified line from right file only ==
== Convert UTF-16 ittle-endian text, with CRLF line terminators to UTF-8 ==
{{{
$ file HUA-MDS9148s-00_2021-11-12_8_43_28.log
HUA-MDS9148s-00_2021-11-12_8_43_28.log: Unicode text, UTF-16, little-endian text, with CRLF line terminators
 merlyn@brightmoon ~/Downloads
 $ iconv -f UTF-16LE -t UTF-8 HUA-MDS9148s-00_2021-11-12_8_43_28.log | head
[BEGIN] 2021/11/12 8:43:40
HUA-MDS9148s-00# show interface fc1/1,fc1/5,fc1/9,fc1/13
fc1/1 is up
    Port description is cnhuam0otc01-01-9a
    Hardware is Fibre Channel, SFP is short wave laser w/o OFC (SN)
    Port WWN is 20:01:00:3a:9c:68:21:10
    Admin port mode is auto, trunk mode is off
    snmp link state traps are enabled
    Port mode is F, FCID is 0x320100
    Port vsan is 100
}}}
== VLAN interface ==
{{{
ip link add link enp0s31f6 name eth0 type vlan id 2092
ip addr add 10.97.2.235/24 brd 10.97.2.255 dev eth0
ip link set dev eth0 up
}}}

== How to find WWN, WWNN and WWPN number of HBA card in Linux ==
{{{
cat /sys/class/fc_host/host*/port_name

systool -c fc_host -v | egrep "port_name|port_state|speed "
}}}

== Performance ==
https://cromwell-intl.com/open-source/performance-tuning/file-systems.html

== Diff, show modified line from right file only ==
Line 115: Line 150:
== How to change the output color of echo in Linux ==
https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux
Line 116: Line 154:
=== How do I insert a space every four characters in a long line? ===
{{{
$ echo "foobarbazblargblurg" | fold -w4 | paste -sd' ' -
}}}
=== You can make a copy ===
  * of /etc/init.d before hand, or provide a suffix to sed's '-i'
{{{
# sed -i.bak -- '1s/runscript/openrc-run/' /etc/init.d/*
}}}
Line 130: Line 178:
=== Add a column to any position in a file in unix [using awk or sed] ===
 awk -v FS='|' -v OFS='|' '{$3=$3"|"4} 1' 1.txt
Line 332: Line 381:
=== two network card with gateway ===

/TwoNetworkCardWithGateway
Line 503: Line 555:
  * Command: mklabel label-type
{{{
Creates a new disk label, of type label-type. The new disk label will have no partitions. This command (normally) won’t technically destroy your data, but it will make it basically unusable, and you will need to use the rescue command (see Related information) to recover any partitions. Parted works on all partition tables. 1

label-type must be one of these supported disk labels:

    bsd
    loop (raw disk access)
    gpt
    mac
    msdos
    pc98
    sun
}}}
Line 510: Line 577:
= Troubleshooting =
== sudo: sorry, you must have a tty to run sudo ==
No panic, there is an easy fix! tty. This is generally enforced by having Defaults requiretty in the /etc/sudoers.

To disable requiretty globally or to a single command, you have two options:

    Replace Defaults requiretty by Defaults !requiretty in your /etc/sudoers. This will impact your global sudo configuration.

Alternatively, you can change this configuration at a per user, per group or per command basis
{{{
Defaults!/path/to/my/bin !requiretty
Defaults:myuser !requiretty
}}}
    Connect by ssh using -t options

From man ssh:

     -t Force pseudo-tty allocation. This can be used to execute arbitrary screen-based programs on a remote
             machine, which can be very useful, e.g. when implementing menu services. Multiple -t options force
             tty allocation, even if ssh has no local tty.


== Short tip: Removing orphaned SAN multipath devices under Enterprise Linux ==
  * https://access.redhat.com/solutions/47438
  * https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html-single/dm_multipath/#config_file_blacklist
  * https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/storage_administration_guide/removing_devices
{{{
# vi /etc/multipath.conf

# service multipathd reload

# multipath -l

After removing the LUN in the SAN backend, a unnamed LUN was added to the multipath topology. Removing this device was not possible as it seemed to be in use:

# multipath -f mpathf


To remove the dead device, the following commands needed to be executed:
# dmsetup remove -f mpathf
# multipath -f mpathf

}}}

== Change default network name (ens33) to “eth0” in Centos7/RHEL7 ==

  * net.ifnames=0 biosdevname=0
{{{
[root@dns-server-01 mnt]# cat /etc/default/grub
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="rd.lvm.lv=ol/root rd.lvm.lv=ol/swap rhgb quiet net.ifnames=0 biosdevname=0
"
GRUB_DISABLE_RECOVERY="true"

}}}

{{{
[root@dns-server-01 mnt]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-327.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-327.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.8.13-98.7.1.el7uek.x86_64
Found initrd image: /boot/initramfs-3.8.13-98.7.1.el7uek.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-3dd58864573848458a5b2f45438633d1
Found initrd image: /boot/initramfs-0-rescue-3dd58864573848458a5b2f45438633d1.img
done
}}}

== How to Remove a Dead Mulitpath Device without Reboot in CentOS/RHEL ==
  1. remove the device map and replace the table with one that fails all I/O.

  * For example:

# dmesetup remove -f 360060e80166bac0000016bac000000da

  1. remove the multipath device.

  * For example:

# multipath -f 360060e80166bac0000016bac000000da

  1. Verify the deletion of the dead multipath device.

# multipath -ll





== Under what conditions should the 'start_udev' command be run? ==
https://access.redhat.com/solutions/221243

  * We run start_udev as part of the storage allocation procedure that we have. It works, but it can be disruptive if an oracle DB instance is up and running (the listener interfaces briefly disappear). Our RH versions that we certified for SAN are 4u5, 4u8, 5.4 and 5.5.

  * Nobody should ever run start_udev, only rc.sysinit should call start_udev.

== udev How to get rid of or remove the multipath device without rebooting the server, rescanning the scsi bus, or restarting multipathd ==
https://access.redhat.com/solutions/3941?page=1

 How to rescan the SCSI bus to add or remove a SCSI device without rebooting the computer
{{{
     # multipath -f multipath-device
     # blockdev --flushbufs device
     # echo 1 > /sys/block/device-name/device/delete
}}}


== fsck ==
{{{
Try: fsck -pvcf -- will force a verbose check for bad blocks and automatically repair. If you still have issues then your HDD might have physical problems.
}}}

== Possible Causes of Ethernet Errors ==
{{{
Collisions: Signifies when the NIC card detects itself and another server on the LAN attempting data transmissions at the same time. Collisions can be expected as a normal part of Ethernet operation and are typically below 0.1% of all frames sent. Higher error rates are likely to be caused by faulty NIC cards or poorly terminated cables.

Single Collisions: The Ethernet frame went through after only one collision

Multiple Collisions: The NIC had to attempt multiple times before successfully sending the frame due to collisions.

CRC Errors: Frames were sent but were corrupted in transit. The presence of CRC errors, but not many collisions usually is an indication of electrical noise. Make sure that you are using the correct type of cable, that the cabling is undamaged and that the connectors are securely fastened.

Frame Errors: An incorrect CRC and a non-integer number of bytes are received. This is usually the result of collisions or a bad Ethernet device.

FIFO and Overrun Errors: The number of times that the NIC was unable of handing data to its memory buffers because the data rate the capabilities of the hardware. This is usually a sign of excessive traffic.

Length Errors: The received frame length was less than or exceeded the Ethernet standard. This is most frequently due to incompatible duplex settings.

Carrier Errors: Errors are caused by the NIC card losing its link connection to the hub or switch. Check for faulty cabling or faulty interfaces on the NIC and networking equipment.
}}}

== Resource temporarily unavailable ==
{{{
  Resolution

    Check /etc/security/limits.conf and all files in /etc/security/limits.d/ for the current setting of the nproc value
    Extend the nproc value. This can be done in /etc/security/limits.conf or in any file in a file in /etc/security/limits.d/.
    Example of /etc/security/limits.conf:
}}}
https://gerardnico.com/wiki/linux/limits.conf
{{{
   Example of /etc/security/limits.conf file

* hard nofile 65535
* soft nofile 4096
@student hard nproc 16384
@student soft nproc 2047

A soft limit is like a warning and hard limit is a real max limit. For example, following will prevent anyone in the student group from having more than 50 processes, and a warning will be given at 30 processes.

@student hard nproc 50
@student soft nproc 30
}}}
Line 517: Line 740:

== Shadowsocks ==
https://shadowsocks.be/9.html
https://suiyuanjian.com/139.html

== systemd disable servers ==
  * The correct command to totally disable a service is systemctl mask wpa_supplicant.service
systemctl mask wpa_supplicant.service

Contents

  1. Linux TIPS
    1. Convert UTF-16 ittle-endian text, with CRLF line terminators to UTF-8
    2. VLAN interface
    3. How to find WWN, WWNN and WWPN number of HBA card in Linux
    4. Performance
    5. Diff, show modified line from right file only
    6. config RHEL services
    7. Connecting a Bluetooth device for serial communication
    8. RAID
    9. X11 putty
    10. How can I dual-boot Windows 10 and Linux
    11. Enter single usermode
    12. Convert audio to text
    13. how to export outlook exchange calendar to my google calendar
    14. show bonding status
    15. mpv about
    16. How to change the output color of echo in Linux
    17. Sed & Awk About
      1. How do I insert a space every four characters in a long line?
      2. You can make a copy
      3. Extract File Basename Without Path and Extension in Bash
      4. Add a column to any position in a file in unix [using awk or sed]
      5. How to insert text before the first line of a file
      6. Sed delete dos CR/LF line
      7. To remove all whitespace (including tabs) from left to first word
      8. sed replace spaces with single space
      9. remove all unwanted blank space then SORT it
      10. add/replace within <<<&>>>
    18. Find About
      1. 把找到的文件复制到另一个地方
      2. Find out all the jpg images and archive it
      3. create symbol link from DIR
      4. 把目录下的包含大写字母的文件列出来
      5. 把目录下所有iso文件找出来并计算总大小(GB)
      6. 查找20100401时更改过的文件
    19. Niubility Tool Netcat
      1. Transfer file(s)
      2. As Port Scanner
    20. history how to use
    21. some keycodes err will resolve
      1. For my HASEE-F4200
    22. Safe Copying
    23. SMB About
    24. ss AND netstat && route && ip
      1. Add route gateway
      2. two network card with gateway
    25. hdparm
    26. If your swapdisk is less than a 1GB, then
    27. Writing the actual CD
      1. List content of ISO file
    28. Sort about
    29. Shuf about
    30. Paste about
    31. Join about
    32. What is "NR==FNR" in awk
    33. urxvt run console application
    34. Wireless reject due to mismatch with WPA/WPA2
    35. Convert png/jpeg to movie(mpeg,mpg,avi,gif)
    36. Rename about
      1. Upper to Lower Case
    37. 降低屏幕蓝光的小工具
    38. app-crypt/letsencrypt
    39. celestia
    40. ssh about
    41. Serial Monitor
    42. ALSA always on mute after startup
    43. tcpdump how to
    44. Reset Your Forgotten Linux Password in 2 Minutes or Less
    45. parted
  2. Troubleshooting
    1. sudo: sorry, you must have a tty to run sudo
    2. Short tip: Removing orphaned SAN multipath devices under Enterprise Linux
    3. Change default network name (ens33) to “eth0” in Centos7/RHEL7
    4. How to Remove a Dead Mulitpath Device without Reboot in CentOS/RHEL
    5. Under what conditions should the 'start_udev' command be run?
    6. udev How to get rid of or remove the multipath device without rebooting the server, rescanning the scsi bus, or restarting multipathd
    7. fsck
    8. Possible Causes of Ethernet Errors
    9. Resource temporarily unavailable
    10. References
    11. Shadowsocks
    12. systemd disable servers

Linux TIPS

Convert UTF-16 ittle-endian text, with CRLF line terminators to UTF-8

$ file HUA-MDS9148s-00_2021-11-12_8_43_28.log
HUA-MDS9148s-00_2021-11-12_8_43_28.log: Unicode text, UTF-16, little-endian text, with CRLF line terminators
 merlyn@brightmoon ~/Downloads
 $ iconv -f UTF-16LE -t UTF-8 HUA-MDS9148s-00_2021-11-12_8_43_28.log | head
[BEGIN] 2021/11/12 8:43:40
HUA-MDS9148s-00# show interface fc1/1,fc1/5,fc1/9,fc1/13
fc1/1 is up
    Port description is cnhuam0otc01-01-9a
    Hardware is Fibre Channel, SFP is short wave laser w/o OFC (SN)
    Port WWN is 20:01:00:3a:9c:68:21:10
    Admin port mode is auto, trunk mode is off
    snmp link state traps are enabled
    Port mode is F, FCID is 0x320100
    Port vsan is 100

VLAN interface

ip link add link enp0s31f6 name eth0 type vlan id 2092
ip addr add 10.97.2.235/24 brd 10.97.2.255 dev eth0
ip link set dev eth0 up

How to find WWN, WWNN and WWPN number of HBA card in Linux

cat /sys/class/fc_host/host*/port_name

systool -c fc_host -v | egrep "port_name|port_state|speed "

Performance

https://cromwell-intl.com/open-source/performance-tuning/file-systems.html

Diff, show modified line from right file only

diff --unchanged-line-format= --old-line-format= --new-line-format='%L' a b

config RHEL services

service=(crond network ntpd rsyslog sshd sysstat irqbalance)
chkconfig --list | awk '{ print $1 }' | xargs -n1 -I@ chkconfig @ off
echo ${service[@]} | xargs -n1 | xargs -I@ chkconfig @ on

Connecting a Bluetooth device for serial communication

rfcomm0 {
  # Automatically bind the device at startup
  bind no;
  # Bluetooth address of the device
  device 11:22:33:44:55:66;
  # RFCOMM channel for the connection
  channel 3;
  # Description of the connection
  comment "This is Device 1's serial port.";
}

Scan for bluetooth devices:

hcitool scan
Scanning ...
    20:15:12:08:62:95   HC-06

Bind using rfcomm

sudo rfcomm bind 0 20:15:12:08:62:95 1

NB: bind 0 refers to device number 0 (rfcomm0) and 1 is the channel. 

* Pair using bluetoothctl:

    power on
    agent on
    scan on
    ... wait ...
    scan off
    pair <dev>

Create serial device: rfcomm bind 0 <dev>

You should now have /dev/rfcomm0.

RAID

RAID 10

RAID 1+0 (or 10) is a mirrored data set (RAID 1) which is then striped (RAID 0), hence the "1+0" name. A RAID 1+0 array requires a minimum of four drives – two mirrored drives to hold half of the striped data, plus another two mirrored for the other half of the data. In Linux, MD RAID 10 is a non-nested RAID type like RAID 1 that only requires a minimum of two drives and may give read performance on the level of RAID 0.

RAID 01

RAID 0+1 (or 01) is a striped data set (RAID 0) which is then mirrored (RAID 1). A RAID 0+1 array requires a minimum of four drives: two to hold the striped data, plus another two to mirror the first pair.

X11 putty

enable X11 Forward

  • then

[root@node1 ~]# export DISPLAY=:0

How can I dual-boot Windows 10 and Linux

http://askubuntu.com/questions/666631/how-can-i-dual-boot-windows-10-and-ubuntu-on-a-uefi-hp-notebook

https://archives.gentoo.org/gentoo-user/message/a6c3d40e8827f65df098269e01186b59

http://unix.stackexchange.com/questions/316602/how-to-properly-dualboot-opensuse-and-windows-10

Enter single usermode

rw init=/bin/bash

Convert audio to text

how to export outlook exchange calendar to my google calendar

http://oregonstate.edu/helpdocs/faq/how-do-i-export-my-outlook-exchange-calendar-my-google-calendar

If you are on Windows PC: Open up your Microsoft Outlook program

If you are on a Mac OS X PC: Go to https://exmail.oregonstate.edu/owa

    Click on Calendar in the lower left corner
    You should see all your calendars in front of you. On the left side of the window, you should see the list of calendars and their names. Under My Calendars, right click the one you wish to add to your Google account.
    After right clicking your chosen calendar, right click, go Share > Publish This Calendar (Publish This Calendar to the Internet)
    A new window will pop up. Select the options for which best suit you. 
    When complete, press Start Publishing in the lower right corner.
    A couple of urls will show up for you to copy. Find the one that ends in .ics and copy that whole url.
    Go to Google Calendar
    When logged in to view your calendar, go find Other Calendars on the left side of the window
    After finding Other Calendars, there should be a box with a triangle in it to the right of the text. Click that box and find "Add by URL".
    A popup will show up. In this popup, you want insert the .ics URL from your Outlook here.
    Press Add Calendar below.

If you would like to stop publishing your calendar and no longer receive updates to your Google Calendar you can follow these directions:

http://oregonstate.edu/helpdocs/e-mail/exchange-outlook-oregonstateedu/publishing-exchange-calendars

show bonding status

watch cat /proc/net/bonding/bond0

mpv about

$ mpv --secondary-sid=2 --sub-file=tlf-jerrymaguire.bd.eng.srt --sub-file=tlf-jerrymaguire.cht.srt Jerry\ Maguire\ 1996\ 1080p\ BluRay\ x264\ AAC\ -\ Ozlem.mp4

How to change the output color of echo in Linux

https://stackoverflow.com/questions/5947742/how-to-change-the-output-color-of-echo-in-linux

Sed & Awk About

How do I insert a space every four characters in a long line?

$ echo "foobarbazblargblurg" | fold -w4 | paste -sd' ' -

You can make a copy

  • of /etc/init.d before hand, or provide a suffix to sed's '-i'

# sed -i.bak -- '1s/runscript/openrc-run/' /etc/init.d/*

Extract File Basename Without Path and Extension in Bash

$ s=/the/path/foo.txt
$ echo ${s##*/}
foo.txt
$ s=${s##*/}
$ echo ${s%.txt}
foo
$ echo ${s%.*}
foo

fbname=$(basename "$1" .txt)
echo "$fbname"

Add a column to any position in a file in unix [using awk or sed]

  • awk -v FS='|' -v OFS='|' '{$3=$3"|"4} 1' 1.txt

How to insert text before the first line of a file

  • I've been looking around sed command to add text into a file in a specific line. This works adding text after line 1:

sed '1 a\

  • Use sed's insert (i) option which will insert the text in the preceding line.

sed '1 i\

Sed delete dos CR/LF line

sed 's/.$//' file > out 
sed 's/\x0D$//' file > out

To remove all whitespace (including tabs) from left to first word

echo "     This is a test" | sed -e 's/^[ \t]*//'
sed  '/\#/d;/^$/d' /etc/nginx/nginx.conf

sed replace spaces with single space

sed -e "s/ \+/ /g;/^$/d" < ml.txt  > mll.txt
sed 's/ \{1,\}/ /g' 

http://superuser.com/questions/241018/how-to-replace-multiple-spaces-by-one-tab

remove all unwanted blank space then SORT it

sed 's/ /\n/g' < list  | sort

add/replace within <<<&>>>

# & replaces whatever matches with the given REGEXP.
$ sed 's@^.*$@<<<&>>>@g' path.txt
<<</usr/kbos/bin:/usr/local/bin:/usr/jbin/:/usr/bin:/usr/sas/bin>>>
<<</usr/local/sbin:/sbin:/bin/:/usr/sbin:/usr/bin:/opt/omni/bin:>>>
<<</opt/omni/lbin:/opt/omni/sbin:/root/bin>>>
$ sed 's@/usr/bin@&/local@g' path.txt
/usr/local/sbin:/sbin:/bin/:/usr/sbin:/usr/bin/local:/opt/omni/bin:
/opt/omni/lbin:/opt/omni/sbin:/root/bin

Find About

把找到的文件复制到另一个地方

find /mnt/sda7/software_linux/ -name "*.exe" | xargs -i cp {} /home/ftp/incoming/
find /mnt/sda7/software_linux/ -name "*.exe" -exec cp '{}' /home/ftp/ ';'
find cacti-xxxx -type d -exec mkdir -p utf/{} ';'
find cacti-xxxx -type f -exec iconv -f GB2312 -t UTF-8 {} -o utf/{} ';'
find /home/user1 -name '*.txt' | xargs cp -av --target-directory=/home/backup/ --parents 

Find out all the jpg images and archive it

find /var/log -name '*.log' | tar cv --files-from=- | bzip2 -9 > log.tar.bz2 
find / -name *.jpg -type f -print | xargs tar -cvzf images.tar.gz

find /mnt/data/media/* -maxdepth 0 -type d -exec ln -sv '{}' . \;

把目录下的包含大写字母的文件列出来

find /usr/share/ -type f | xargs ls -l | grep '[:upper:]' | less -r
find . -maxdepth 2 -size +100M -exec ls -lh "{}" \;

把目录下所有iso文件找出来并计算总大小(GB)

find /srv/ /mnt/media/ -name "*.iso" | xargs ls -lk | echo `awk '{a+=$5}END {print a}'`/1024/1024 | bc
find /srv/ /mnt/media/ -name "*.iso" | xargs ls -lk | awk '{a+=$5}END {print "Total sum is", a/1024/1024"GB"}'
find /srv/ /mnt/media/ -name "*.iso" -printf "%s\n" 2>/dev/null | awk '{a+=$1}END { print "Total sum is", a/1024/1024/1024"GB\nTotal time is :"}'

== Find files out then Copy files with sequence number ===

find . -name "*tgz" -type f -exec ls -Sr '{}' \; |awk '{system("cp -v "$0" "NR)}'

查找20100401时更改过的文件

cat >> 20100401.sh <<"EOF"
FILE=`find ./ -name "*.tex"`
ls -l --full-time $FILE 2>/dev/null
grep "2010-04-01"
EOF

Niubility Tool Netcat

Transfer file(s)

  • Suppose you want to send files in /data from computer A with IP 192.168.2.111 to computer B(with any IP), It's as simple as this:

server: $ tar -cf - /data | nc -l -p 6666
client: $ nc 192.168.2.111 6666 | tar -xf -
  • A single file can be sent even easier.

server: $ cat file | nc -l -p 6666
client: $ nc 192.168.2.111 6666 > file
  • And you may copy and restore whole disk with nc:

server: $ cat /dev/sda | nc -l -p 6666
cliend: $ nc 192.168.2.111 6666 > /dev/sda

As Port Scanner

nc -vv -z 127.0.0.1 8079-8081

history how to use

$ history | grep 'ipt'
2    iptables -L -n -v -t nat

$ !2 # will execute the iptables command * MarkS, yes I know a way to make history contain only uniques. Do the following:

export HISTIGNORE="&"
That will make history not to save duplicate consecutive entries!

some keycodes err will resolve

  • Added new keycodes for sk2506 HP multimedia 23-key keyboard

setkeycodes e016 235
setkeycodes e01e 158
setkeycodes e012 146
setkeycodes e014 148
setkeycodes e015 149
setkeycodes e02d 173
setkeycodes e018 236
setkeycodes e026 238
setkeycodes e017 227
setkeycodes e01f 159
setkeycodes e025 239
setkeycodes e023 237

For my HASEE-F4200

atkbd.c: Unknown key released (translated set 2, code 0xd8 on isa0060/serio0).
atkbd.c: Use 'setkeycodes e058 <keycode>' to make it known.
getkeycodes will show you codes!

then

setkeycodes e058 125

Safe Copying

if [ -f $2 ]
then
        echo "$2 is exists. Do you want to overwrite it? (y/n)"
        read yn
        if [ $yn = "N" || $yn = "n" ]
        then
                exit 0
        fi
fi
cp $1 $2

SMB About

mount.cifs //nas.systec.com.cn/Share /mnt/zip/ -o user=cml,domain=systec.com.cn

smbmount //192.168.2.51/D memory/ -o iocharset=cp936,user=xxxx,pass= --verbose
smbclient -U user -I 192.168.16.229 -L //smbshare/    # List the shares
mount -t smbfs -o username=winuser //smbserver/myshare /mnt/smbshare
mount -t cifs -o username=winuser,password=winpwd //192.168.16.229/myshare /mnt/share
sudo mount -t cifs -o username=${USER},password=${PASSWORD},uid=<user>,gid=<group> //server-address/folder /mount/path/on/ubuntu
[[http://unix.stackexchange.com/questions/68079/mount-cifs-network-drive-write-permissions-and-chown]]

ss AND netstat && route && ip

  • This program is obsolete. Replacement for netstat is ss. Replacement for netstat -r is ip route. Replacement for netstat -i is ip -s link.Replacement for netstat -g is ip maddr.

ss -r
ip -s
ip maddr
netstat -lptu
netstat -antup

Add route gateway

route add a.b.c.d dev wlan0
ifconfig eth0 128.100.75.111 broadcast 128.100.75.0 netmask 255.255.255.0
route add -net 128.100.75.0 netmask 255.255.255.0
route add default gw 10.7.84.1 dev wlan0

two network card with gateway

/TwoNetworkCardWithGateway

hdparm

hdparm -a 256 -d 1 -r 0 -u 0 -m 2 -c 1 -A 1 -K 0 -P 0 -X 0 -W 0 -S 0 /dev/sda 

will enable DMA ,32bit support, Sector count for multiple sector I/O to 2

If your swapdisk is less than a 1GB, then

dd if=/dev/zero of=/directory/with/much/free/space/tempswap bs=1k count=1000000
chmod 600 tempswap
mke2fs tempswap
mkswap tempswap
swapon tempswap

Writing the actual CD

List content of ISO file

isoinfo -f -R -i cflinux-1.0.iso

  • Assuming that you've got cdrecord installed and configured for your cd-writer

type:

cdrecord --scanbus
cdrecord -v speed=<desired writing speed> dev=<path to your writers generic scsi device> boot.iso

Sort about

  • Generate a tags file in case-insensitive sorted order.

find src -type f -print0 | sort -z -f | xargs -0 etags --append

Shuffle a list of directories, but preserve the order of files within each directory. For instance, one could use this to generate a music playlist in which albums are shuffled but the songs of each album are played in order.

ls */*.mp3 | sort -t / -k 1,1R -k 2,2
sort -n -k 2 -t : facebook.txt
sort: ls -l | sort -nr +4
cut: cut -f1 -d':' < /etc/passwd        

Shuf about

shuf <<EOF
x
xx
xxx
EOF
shuf -i 1-100
shuf -e clubs hearts diamonds spades

Paste about

  • For example

     $ cat num2
     1
     2
     $ cat let3
     a
     b
     c
     $ paste num2 let3
     1       a
     2       b
             c
$ paste -d '%_' num2 let3 num2
          1%a_1
          2%b_2
          %c_

Join about

  • For example:

     $ cat file1
     a a1
     c c1
     b b1
     $ cat file2
     a a2
     c c2
     b b2
     $ join file1 file2
     a a1 a2
     c c1 c2
     b b1 b2

What is "NR==FNR" in awk

 26
down vote
        

Look for keys (first word of line) in file2 that are also in file1.
Step 1: fill array a with the first words of file 1:

awk '{a[$1];}' file1

Step 2: Fill array a and ignore file 2 in the same command. For this check the total number of records until now with the number of the current input file.

awk 'NR==FNR{a[$1]}' file1 file2

Step 3: Ignore actions that might come after } when parsing file 1

awk 'NR==FNR{a[$1];next}' file1 file2 

Step 4: print key of file2 when found in the array a

awk 'NR==FNR{a[$1];next} $1 in a{print $1}' file1 file2

urxvt run console application

urxvt -e bash -c geany_run_script.sh
urxvt -hold -e bash -c "./application"

https://bbs.archlinux.org/viewtopic.php?id=63516

Wireless reject due to mismatch with WPA/WPA2

Convert png/jpeg to movie(mpeg,mpg,avi,gif)

convert -delay 10 -loop 0 *.png animation.gif

Rename about

Upper to Lower Case

rename 'y/A-Z/a-z/' *.HTML

降低屏幕蓝光的小工具

redshift

app-crypt/letsencrypt

Let's Encrypt 是一个新的数字证书认证机构,它通过自动化的过程消除创建和安装证书的复杂性,为网站提供免费的 SSL/TLS 证书。

celestia

实时太空模拟

ssh about

  • Unable to negotiate with 192.168.0.195: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1

ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 root@192.168.0.195

Serial Monitor

socat /dev/ttyS0,raw,echo=0 SYSTEM:'tee input.txt | socat - "PTY,link=/tmp/ttyV0,raw,echo=0,waitslave" | tee output.txt'

screen /dev/tty.usbserial-blahblah 9600

ALSA always on mute after startup

Disabling the module "module-device-restore" in /etc/pulse/default.pa solves the "mute" problem.

tcpdump how to

https://forum.ivorde.com/tcpdump-how-to-to-capture-only-icmp-ping-echo-requests-t15191.html

https://danielmiessler.com/study/tcpdump/

Reset Your Forgotten Linux Password in 2 Minutes or Less

Grub OR LILO + rw init=/bin/bash

parted

  • Command: mklabel label-type

Creates a new disk label, of type label-type. The new disk label will have no partitions. This command (normally) won’t technically destroy your data, but it will make it basically unusable, and you will need to use the rescue command (see Related information) to recover any partitions. Parted works on all partition tables. 1

label-type must be one of these supported disk labels:

    bsd
    loop (raw disk access)
    gpt
    mac
    msdos
    pc98
    sun 

How to align partitions for best performance using parted

parted /dev/sdb mkpart primary 0% 100%
parted /dev/sda mkpart oracle-data ext4 250GB 100%
parted /dev/sdb print

Troubleshooting

sudo: sorry, you must have a tty to run sudo

No panic, there is an easy fix! tty. This is generally enforced by having Defaults requiretty in the /etc/sudoers.

To disable requiretty globally or to a single command, you have two options:

  • Replace Defaults requiretty by Defaults !requiretty in your /etc/sudoers. This will impact your global sudo configuration.

Alternatively, you can change this configuration at a per user, per group or per command basis

Defaults!/path/to/my/bin !requiretty
Defaults:myuser !requiretty
  • Connect by ssh using -t options

From man ssh:

  • -t Force pseudo-tty allocation. This can be used to execute arbitrary screen-based programs on a remote
    • machine, which can be very useful, e.g. when implementing menu services. Multiple -t options force tty allocation, even if ssh has no local tty.

Short tip: Removing orphaned SAN multipath devices under Enterprise Linux

# vi /etc/multipath.conf

# service multipathd reload

# multipath -l

After removing the LUN in the SAN backend, a unnamed LUN was added to the multipath topology. Removing this device was not possible as it seemed to be in use:

# multipath -f mpathf


To remove the dead device, the following commands needed to be executed:
# dmsetup remove -f mpathf
# multipath -f mpathf

Change default network name (ens33) to “eth0” in Centos7/RHEL7

  • net.ifnames=0 biosdevname=0

[root@dns-server-01 mnt]# cat /etc/default/grub 
GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="rd.lvm.lv=ol/root rd.lvm.lv=ol/swap rhgb quiet net.ifnames=0 biosdevname=0
"
GRUB_DISABLE_RECOVERY="true"

[root@dns-server-01 mnt]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-327.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-327.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.8.13-98.7.1.el7uek.x86_64
Found initrd image: /boot/initramfs-3.8.13-98.7.1.el7uek.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-3dd58864573848458a5b2f45438633d1
Found initrd image: /boot/initramfs-0-rescue-3dd58864573848458a5b2f45438633d1.img
done

How to Remove a Dead Mulitpath Device without Reboot in CentOS/RHEL

  1. remove the device map and replace the table with one that fails all I/O.
  2. For example:

# dmesetup remove -f 360060e80166bac0000016bac000000da

  1. remove the multipath device.
  2. For example:

# multipath -f 360060e80166bac0000016bac000000da

  1. Verify the deletion of the dead multipath device.

# multipath -ll

Under what conditions should the 'start_udev' command be run?

https://access.redhat.com/solutions/221243

  • We run start_udev as part of the storage allocation procedure that we have. It works, but it can be disruptive if an oracle DB instance is up and running (the listener interfaces briefly disappear). Our RH versions that we certified for SAN are 4u5, 4u8, 5.4 and 5.5.
  • Nobody should ever run start_udev, only rc.sysinit should call start_udev.

udev How to get rid of or remove the multipath device without rebooting the server, rescanning the scsi bus, or restarting multipathd

https://access.redhat.com/solutions/3941?page=1

  • How to rescan the SCSI bus to add or remove a SCSI device without rebooting the computer

     # multipath -f multipath-device
     # blockdev --flushbufs device
     # echo 1 >  /sys/block/device-name/device/delete

fsck

Try: fsck -pvcf -- will force a verbose check for bad blocks and automatically repair. If you still have issues then your HDD might have physical problems.

Possible Causes of Ethernet Errors

Collisions: Signifies when the NIC card detects itself and another server on the LAN attempting data transmissions at the same time. Collisions can be expected as a normal part of Ethernet operation and are typically below 0.1% of all frames sent. Higher error rates are likely to be caused by faulty NIC cards or poorly terminated cables.

Single Collisions: The Ethernet frame went through after only one collision

Multiple Collisions: The NIC had to attempt multiple times before successfully sending the frame due to collisions.

CRC Errors: Frames were sent but were corrupted in transit. The presence of CRC errors, but not many collisions usually is an indication of electrical noise. Make sure that you are using the correct type of cable, that the cabling is undamaged and that the connectors are securely fastened.

Frame Errors: An incorrect CRC and a non-integer number of bytes are received. This is usually the result of collisions or a bad Ethernet device.

FIFO and Overrun Errors: The number of times that the NIC was unable of handing data to its memory buffers because the data rate the capabilities of the hardware. This is usually a sign of excessive traffic.

Length Errors: The received frame length was less than or exceeded the Ethernet standard. This is most frequently due to incompatible duplex settings.

Carrier Errors: Errors are caused by the NIC card losing its link connection to the hub or switch. Check for faulty cabling or faulty interfaces on the NIC and networking equipment. 

Resource temporarily unavailable

  Resolution

    Check /etc/security/limits.conf and all files in /etc/security/limits.d/ for the current setting of the nproc value
    Extend the nproc value. This can be done in /etc/security/limits.conf or in any file in a file in /etc/security/limits.d/.
    Example of /etc/security/limits.conf:

https://gerardnico.com/wiki/linux/limits.conf

   Example of /etc/security/limits.conf file

*               hard    nofile          65535
*               soft    nofile          4096
@student        hard    nproc           16384
@student        soft    nproc           2047

A soft limit is like a warning and hard limit is a real max limit. For example, following will prevent anyone in the student group from having more than 50 processes, and a warning will be given at 30 processes.

@student        hard    nproc           50
@student        soft    nproc           30

References

http://www.tecmint.com/free-online-linux-learning-guide-for-beginners/

http://rainbow.chard.org/2013/01/30/how-to-align-partitions-for-best-performance-using-parted

Shadowsocks

https://shadowsocks.be/9.html https://suiyuanjian.com/139.html

systemd disable servers

  • The correct command to totally disable a service is systemctl mask wpa_supplicant.service

systemctl mask wpa_supplicant.service

désert/Linux (last edited 2021-11-12 15:14:40 by merlyn)