Tag Archives: shell

[Android test] solution for error closed after the carriage return of the ADB shell

2019 Unicorn enterprise heavily recruited Python engineer standard & GT; > >

Phenomenon 1: In the process of Monkey test by connecting USB with mobile phone, start a CMD window to input again, and error Closed appears after ADB shell returns. In some cases, this can happen with some cell phones.
Phenomenon 2: Unable to install ***. Apk on device ‘019417a3’: Unable to open Sync Connection!
Personally, I think the reasons for both phenomena are the same.
The solution is as follows:

One: Restart your computer, then look up your phone on your computer and start Eclipse
Second: Mobile phone – Settings – applications – development – USB debugging on and off again
Third: restart the phone, usb debugging on and off again.
Fourth: Try “adb kill-server” and then “adb start-Server “under CMD.
Personally, the second and third methods are more practical

Reproduced in: https://my.oschina.net/u/199776/blog/330604

Solution to prompt “error opening terminal: xterm.” when making menuconfig

The solution to make Menuconfig is to prompt “Error opening terminal: xterm.

Under Linux environment, make menuconfig or make config commands are used when compiling embedded systems. These commands usually use the ncurses library. If the ncurses library is not installed and set correctly, the following Error message may appear:
Error opening terminal: xterm

Solutions:

1. First make sure that the ncurses library is installed correctly. On debian, Ubuntu, you can use dpkg-l | grep ncurses to see if the ncurses library is installed.
2. If ncurses is already installed, check to see if the TERM and TERMINFO environment variables have been set correctly. If it is not set correctly, you need to set it to the correct value.
$ echo $TERM
$ echo $TERMINFO

For TERMINFO, the path to TERMINFO should be set, such as /usr/share/ TERMINFO or /lib/ TERMINFO. To view Terminfo's storage location with the following instruction:

$whereis terminfo
terminfo: /etc/terminfo /lib/terminfo /usr/share/terminfo /usr/share/man/man5/terminfo.5.gz

See if the terminal information file is saved in the Terminfo directory: It is usually divided into A, B, C, D... Z these alphabetic directories, each containing term information beginning with that letter. For example, vT100 is placed in the "V" directory. The term we need must have the term information in the corresponding directory. Once you have identified this information, you can set the TERM and TERMINFO information:

export TERM=xterm
export TERMINFO=/lib/terminfo

The Settings above, must ensure that the/usr/share/terminfo term existing in the information, and/usr/share/terminfo/v/vt100 exists.
Regarding the setting of terms, it may need to be set to different terms such as Linux, VT100-putty, etc. Linux is commonly used for the Linux console, and vT100-putty is, as the name implies, a VT100 terminal that USES PuTTY to log in remotely.
The following are the values of the TERM and TERMINFO environment variables in the Ubuntu12.10 environment after the problem is resolved.

$ echo $TERM
xterm
$ echo $TERMINFO
/lib/terminfo/

Passwd: authentication token manipulation error in Linux

If in Linux, whether root or ordinary user logs in and changes their password, passwd: Authenticationtoken Manipulation error occurs — the solution to the error:
Root herself failed to change the password

Normal user failed to change password

1. Reporting such an error is: password: authentication token operation error, usually due to the permissions of the password file, but may also be the root directory space is full.

Using the Lsattr command to view the file properties that hold the user and password, you find the I option: (I: Do not arbitrarily change files or directories.) As a result, all users cannot change their passwords because they have no permission to do so.
2. We need to use the chattr command to revoke the I permission, and then modify, it is ok.

3. Then test root and Xiaogang users to change their passwords.
Test the root user to change the password

Test xiaogang users to change their passwords

4. For security reasons, it is better to change the password and protect the file where the user and password are stored.
Also chattr + I /etc/passwd and chattr + I /etc/shadow files
5 ordinary users to modify their passwords, is required, the password must be complex, and in the password dictionary some characters can be set.

syntax error near unexpected token `then’ problem solution

#! /bin/bash
#if program test

echo ‘a:’
read a
If [“$a” = “English”]; then
echo “right”
else
echo “wrong”
fi

I wrote the shell script according to the procedure on the video, but “syntax error near token ‘then'” appeared during the execution. After looking at the syntax error near token’ then’ for half a day, I did not find out the reason. After searching the Internet for a long time, I finally understood the reason: There is no space between if and ‘[‘. In addition, when executing, I also found that there must be space on both sides of’ = ‘, otherwise there will be an error, not a syntax error, but no matter what value is assigned to a, the program will get the statement after if is false, thus resulting in wrong.

When linux installs rpm, it prompts: can’t create transaction lock on /var/lib/rpm/.rpm.lock error

Install the RPM package under Linux with a non-root user. Error can’t create transaction lock on /var/lib/ RPM /.rpm. Lock.

[hadoop@hadoop186 rpm]$ rpm -ivh libconfuse-2.5-4.el5.x86_64.rpm 
Warning: libconfuse-2.5-4.el5.x86_64.rpm: ヘッダ V3 DSA/SHA1 Signature, key ID 217521f6: NOKEY
エラー: can't create transaction lock on /var/lib/rpm/.rpm.lock (許可がありません)

 

Error reason: Permission problem

[hadoop@hadoop186 sbin]$ ll  /var/lib/rpm/
Totally 95584
-rw-r--r--. 1 root root 10678272  7月 10 11:41 2014 Basenames
-rw-r--r--. 1 root root    12288  5月  4 11:58 2014 Conflictname
-rw-r--r--. 1 root root  2170880  7月 10 11:41 2014 Dirnames
-rw-r--r--. 1 root root 10604544  7月 10 11:41 2014 Filedigests
-rw-r--r--. 1 root root    36864  7月 10 11:41 2014 Group
-rw-r--r--. 1 root root    24576  7月 10 11:41 2014 Installtid
-rw-r--r--. 1 root root    86016  7月 10 11:41 2014 Name
-rw-r--r--. 1 root root    24576  5月  5 15:29 2014 Obsoletename
-rw-r--r--. 1 root root 73293824  7月 10 11:41 2014 Packages
-rw-r--r--. 1 root root  1331200  7月 10 11:41 2014 Providename
-rw-r--r--. 1 root root   667648  7月 10 11:41 2014 Provideversion
-rw-r--r--. 1 root root    12288  3月 27 14:11 2014 Pubkeys
-rw-r--r--. 1 root root   512000  7月 10 11:41 2014 Requirename
-rw-r--r--. 1 root root   323584  7月 10 11:41 2014 Requireversion
-rw-r--r--. 1 root root   163840  7月 10 11:41 2014 Sha1header
-rw-r--r--. 1 root root    77824  7月 10 11:41 2014 Sigmd5
-rw-r--r--. 1 root root    12288  3月 27 14:46 2014 Triggername
-rw-r--r--  1 root root    24576  7月 10 11:41 2014 __db.001
-rw-r--r--  1 root root   229376  7月 10 11:41 2014 __db.002
-rw-r--r--  1 root root  1318912  7月 10 11:41 2014 __db.003
-rw-r--r--  1 root root   753664  7月 10 11:41 2014 __db.004

solution:
Enter “su” and password at the terminal, log in root, and log in as root will not be prompted

[hadoop@hadoop186 rpm]$ su - root
パスワード:
[root@hadoop186 ~]# pwd
/root
[root@hadoop186 ~]# cd /home/hadoop/rpm/
[root@hadoop186 rpm]# ll
合計 164
-rw-rw-r--. 1 hadoop hadoop 31792  6月 20 17:00 2014 argtable-2.13-2.el6.x86_64.rpm
-rw-rw-r--  1 hadoop hadoop 87025  7月 10 11:38 2014 libconfuse-2.5-4.el5.x86_64.rpm
-rw-rw-r--  1 hadoop hadoop 15013  7月 10 11:38 2014 libconfuse-devel-2.5-4.el5.x86_64.rpm
-rw-rw-r--. 1 hadoop hadoop 26256  6月 20 17:00 2014 log4c-devel-1.2.4-1.el6.x86_64.rpm
[root@hadoop186 rpm]# rpm -ivh libconfuse-2.5-4.el5.x86_64.rpm 
警告: libconfuse-2.5-4.el5.x86_64.rpm: ヘッダ V3 DSA/SHA1 Signature, key ID 217521f6: NOKEY
準備中...                ########################################### [100%]
   1:libconfuse             ########################################### [100%]
[root@hadoop186 rpm]# rpm -ivh libconfuse-devel-2.5-4.el5.x86_64.rpm
警告: libconfuse-devel-2.5-4.el5.x86_64.rpm: ヘッダ V3 DSA/SHA1 Signature, key ID 217521f6: NOKEY
準備中...                ########################################### [100%]
   1:libconfuse-devel       ########################################### [100%]
[root@hadoop186 rpm]# 

(gedit:10072): dconf-WARNING **: failed to commit changes to dconf: connection closed

Problem: writing a hello.c file in Linux has reported an error

The possible reason is that the GCC source
input was not installed

rpm -q gcc


how to install GCC source in Linux
to write the simplest c program hello.c can refer to the blog below
to create c program hello.c

under root would be considered for normal users, or su-.

Shell script: syntax error: bad for loop variable error resolution

A simple shell script is written in Linux Mint, using for.. do.. Done 1+2+3…… +100 value, the result of “SH-n XXx. sh” syntax detection is always wrong, but can run normally on PC;

Script:

#!/bin/bash
#information
 
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
 
read -p "Please input a num " num
sum=0
for ((a=0; a<=$num; a++))
do 
sum=$(($sum + $a))
done
echo "the sum is ==> $sum"
exit 0

The errors are as follows:

Syntax error: Bad for loop variable

Analysis:
Since ubuntu 6.10, ubuntu has replaced the previous default bash shell with the dash shell; This appears as the /bin/sh link inverted /bin/dash instead of the traditional /bin/bash.

allen@allen-lql ~/workspace/script $ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 Aug 12 14:29 /bin/sh -> dash

So when using SH to perform the detection, dash is actually used, and DASH does not support this C-format for loop writing.

Solutions:
1, change the default shell to bash. (Bash supports for loop in C format)

sudo dpkg-reconfigure dash

choose No

2. Use bash detection directly:

bash -n xxx.sh

3. To ensure the portability of shell scripts, directly change shell scripts and use the for loop format supported by the shell:

for a in `seq $num`


Failed to add /run/systemd/ask-password to directory watch: No space left on device?

cloud server after docker is installed successfully, enter the start command:

sudo service docker start

system threw an exception: Failed to add /run/systemd/ask-password to directory watch: No space left on device

check the server space usage and find that it is not a server space problem. Upon examination, it was found that the following method could be used:

for immediate effect: add monitoring space

on the command line

sudo -i
echo 1048576 > /proc/sys/fs/inotify/max_user_watches
exit

or you can modify the configuration file to make monitoring long term:

sudo vim /etc/sysctl.conf

and then add:

to the end of the file

fs.inotify.max_user_watches=1048576

save and exit, and then enter the start docker command.

Top background execution: Top: failed TTY get error

call the top command in non-interactive mode through other programs or scripts, often appear :
top: failed tty get error

solution: add the -b option to either

-b: Batch mode operation
Starts top in < A1> < AF> Batch mode< A1> < AF> You< which could be useful for sending output from top to other programs or to a file. In this mode, top will not accept input and runs until the iterations limit you< A1> < AF> ve set with the < A1> < AF> -n< A1> < AF> command-line option or until killed.

for example: top-bn 1

nohup top-b | grep init > > top.log & (Top. Log content is displayed slowly)

nohup /usr/bin/top -b | grep init > > top.log & (top. Log content appears fast)

Linux shell gets the file name under the folder

article author: Tyan
blog: noahsnail.com | CSDN | short book

sometimes need to get all the file names under a folder, can be implemented with the program, but open the IDE, compile and run too troublesome, in Linux server usually can not open the IDE, at this time can be implemented with a few lines of simple shell command, the result can be saved in a file.

Shell script is as follows:

#!/bin/bash
# get all filename in specified path

path=$1
files=$(ls $path)
for filename in $files
do
   echo $filename >> filename.txt
done

Common shell (1): shell gets the current time stamp of the system

1. Shell script as follows

current=`date "+%Y-%m-%d %H:%M:%S"`  
timeStamp=`date -d "$current" +%s`   
#将current转换为时间戳,精确到毫秒  
currentTimeStamp=$((timeStamp*1000+`date "+%N"`/1000000)) 
echo $currentTimeStamp

2. Operation effect

3. Note

this in timestamp way has a small error, the need to obtain precise timestamp refer to: https://blog.csdn.net/AQ931752921/article/details/85071221

Several methods of executing multiple commands in Linux shell

can execute more than one command at a time on the command line, in the following categories:

1. Use between each command;

indicates that the execution results of each command will not affect the execution of other commands. In other words, each command will execute,
but there is no guarantee that each command will execute successfully.

cd /home/PyTest/src; python suning.py

2. Use &amp between each command; & Separate
indicates that the following command will only be executed if the previous command succeeds. This ensures that all commands are executed successfully.

cd /home/PyTest/src&&python suning.py

3. Use | or | or | between each command
.

pipe can direct the output of one command to the input of another, allowing two (or more) commands to work in a continuous pipeline, constantly processing text streams. On the command line, we use | for pipes

cd /home/PyTest/123 || echo "error234"
cd /home/PyTest/123 | echo "error234"