Tag Archives: bash

[Solved] Sed Failed to Reference Variable error: extra characters after command

Environment:

Operating system: CentOS
Background: shell script

Question:

sudo sed -n '842,${line}p' /.../file > ./file1

After execution, an error is reported:
– e expression # 1, char 7: extra characters after command.

Solution:

After investigation, it is found that it is OK to replace single quotation marks with double quotation marks, as follows:

sudo sed -n "842,${line}p" /.../file > ./file1

If none of the methods found work, try this one.

Remember that variables cannot be referenced within single quotes.

DONE!

error: C compiler cannot create executables [How to Solve]

Phenomenon:

./configure --prefix=/usr/local/python3.6
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for python3.6... no
checking for python3... no
checking for python... python
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... linux
checking for --without-gcc... no
checking for --with-icc... no
checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in `/tmp/Python-3.6.13':
configure: error: C compiler cannot create executables
See `config.log' for more details

Solution:

1. View log

# cat config.log |grep error
gcc: error: unrecognized command line option '-V'
gcc: fatal error: no input files
gcc: error: unrecognized command line option '-qversion'
gcc: fatal error: no input files
/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/cc1: error while loading shared libraries: libmpfr.so.4: cannot open shared object file: No such file or directory
configure:4005: error: in `/tmp/Python-3.6.13':
configure:4007: error: C compiler cannot create executables

Missing libmpfr.so.4 File

2. Install mpfr

Package name:mpfr-3.1.1-4.el7.x86_64

~# yum install mpfr-3.1.1-4.el7.x86_64 -y
......
Verification:
~# ll /usr/lib64/libmpfr.so.4
libmpfr.so.4      libmpfr.so.4.1.1  
~# ll /usr/lib64/libmpfr.so.4
lrwxrwxrwx 1 root root 16 Sep  7 22:26 /usr/lib64/libmpfr.so.4 -> libmpfr.so.4.1.1

Finally, the problem is solved

[Solved] kubeadm join Cluster Error: error execution phase kubelet-start

preface

An error is reported when adding a k8s-node using kubedm join , as follows:

error execution phase kubelet-start: error uploading crisocket: timed out waiting for the condition

Solution:

1 reset the cluster configuration of this machine

kubeadm reset -f

2 stop service

sudo tee /tmp/test.sh <<-'EOF'
systemctl stop kubelet kube-proxy docker containerd
ps -ef | grep containerd | awk '{print $2}' | xargs -I {} kill -9 {}
rm -rf /etc/systemd/system/kube-proxy.service
rm -rf /etc/systemd/system/kubelet.service
systemctl stop zabbix-agent.service
systemctl disable zabbix-agent.service
systemctl stop node_exporter_custom.service
systemctl disable node_exporter_custom.service
systemctl reset-failed
rm -rf /usr/local/bin/kube*
EOF
chmod +x /tmp/test.sh && bash /tmp/test.sh

3 start docker

systemctl start docker

4 join the cluster

Run kubedm token create -- print-join-command on Master to get token information

Then execute the following command on the node node to rejoin the k8s cluster

# k8s-node
kubeadm join 172.18.12.23:6443 --token okt9c2.edidk4m2yfim31su \
--discovery-token-ca-cert-hash sha256:0a6cb9f97106782102840e142eda33dc3dc071aff1af436f90d43699acdc3751

Success information

5 verify on k8s-master

kubectl get node
kubectl get pod -A

[Solved] Shell loop execute error: syntax error: bad for loop variable

#!/bin/bash

for ((i = 10 ; i>=0 ; i--))
do
	echo $i
done

Syntax error: bad for loop variable

The reason is that since Ubuntu 6.10, Ubuntu has replaced the previous default bash shell with dash shell; It shows that the/bin/sh link reverses/bin/dash instead of the traditional/bin/bash.

Question 1: why #/ Bin/bash doesn’t work?

./execution will read #/ Bin/bash specifies the shell parser, and the script needs execution permission

Executing with SH will not read #/ Bin/bash, which is equivalent to executing the/bin/sh shell script and passing it in as a parameter. The script does not need execution permission, but only reading permission

Solution 1:

Execute sudo dpkg reconfigure dash and select No

Solution 2:

Modify cycle


for i in `seq 1 10`                                                                                                
do                                                                                                               
        echo $i                                                                                                  
done                                                                                                             
         
OR
                                                                                                        
for i in {0..10}                                                                                                 
do                                                                                                               
        echo $i                                                                                                  
done  

[Solved] Ubuntu tab Error: _complete:96: bad math expression: operand expected at end of string

Error content

_complete:96: bad math expression: operand expected at end of string

Cause: Zsh folder permission error

Solution:

    1. view the location of the Zsh folder
compaudit
# my path is:
/usr/local/share/zsh/site-functions
/usr/local/share/zsh

Set folder user group and its user

sudo su
chown -R user.user /usr/local/share/zsh

Set folder permissions

# root
chmod g-w -R zsh/

Restart the command window

Error while Launching activity [How to Solve]

1. Use ADB to write in the package restart program ADB uninstall package name
if there is no ADB command:
(1) create a. Bash_profile file (input touch.Bash_profile)
(2) open the. Bash_profile file (input open – E.Bash_profile)
(3) edit in the open. Bash_profile file: export path = ${path} :/users/your own user name/library/Android/SDK/platform tools
after editing, save and exit
(4) execute the command source. Bash_profile;
(5) enter, and the ADB version will succeed if the version number appears. Finally, execute the ADB uninstall package name, output success, and restart the program

2 at manifest Does the XML declare two activities as launchers

3 in the listing, add your first startup class and filter code, copy the whole intent filter and add it to your first startup class

<activity android:name=".MainActivity">
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />

    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>

linux use sh execute source error [How to Solve]

Error: In the shell script, execute the file with sh and report source: not found

Reason: sh and bash are different shells, there is no source command in sh. So when running with sh or ./, this error will be prompted.

Solution: replace sh with bash, eg. bash test.sh
is to use bash to execute it.

[Solved] Error :: You must put some ‘source‘ URIs in your sources.list

Solution:

Just enter the following three lines.

sudo cp /etc/apt/sources.list /etc/apt/sources.list~
sudo sed -Ei 's/^# deb-src /deb-src /' /etc/apt/sources.list
sudo apt-get update

Users who are not logged in can copy the code below.

sudo cp /etc/apt/sources.list /etc/apt/sources.list~
sudo sed -Ei ‘s/^# deb-src /deb-src /’ /etc/apt/sources.list
sudo apt-get update

Reference:
https://askubuntu.com/questions/496549/error-you-must-put-some-source-uris-in-your-sources-list

Error BC: command not found when git bash runs shell script

catalog:

1. Problem Description: 2. Error reporting reason: 3. Solution:

1. Problem Description:

Under Windows system, an error occurs when running shell script with git bash:

bc: command not found

2. Error reporting reason:

Git is missing the BC module, and git cannot directly install the BC module

3. Solution:

By downloading msys2, download the BC package in msys2 and copy it to git
specific steps:
(1) install msys2 and download the address https://www.msys2.org/
(2) After installation, open the msys2 shell and install BC with the following command

pacman -S bc

(3) Go to the msys64 \ usr \ bin folder under the msys2 installation directory and find bc.exe
(4) copy the bc.exe file to the GIT \ usr \ bin folder under the GIT installation directory
re run the shell script in Git bash, and there will be no BC: command not found error.

The semget function error: errno is set to 28 [How to Solve]

When running semget under Linux to create semaphores, it returns – 1 and the creation fails;

1. This function is a system function. You can only confirm the actual error code with errno, print errno through strError, and return no space left on device. Is the system space insufficient? Insufficient space to create semaphores?

2. Go to errno. H to check the error message enospc corresponding to the actual error code. What does this field mean?

3. Does the semget function have its own error field? Check the function manual: check the man Manual of semget function: a semaphore set has to be created but the system limit for the maximum number of semaphore sets (semmni), or the system-wide maximum number of semaphores. Semaphore exceeds system limit.

It is basically determined that it is caused by the system semaphore. First, temporarily modify the kernel semaphore parameters and run again to see whether it has been solved.

4. The following commands are used in viewing semaphores

#1)The sysctl command can view and set system kernel parameters
# The 4 corresponding values from left to right are SEMMSL, SEMMNS, SEMOPM and SEMMNI.
sysctl -a | grep sem #View the setting value of the system semaphore
kernel.sem = 250 32000 32 128


#2) There are three ways to modify: the numbers are for reference only
echo 610 86620 100 142 > /proc/sys/kernel/sem

sysctl -w kernel.sem="610 86620 100 142"

echo "kernel.sem=610 86620 100 142" >> /etc/sysctl.conf`


#3) View the current semaphore and pid of the system as well as user information, view more information and check --help
ipcs -s -p -c


#4) Delete the semaphore method of the specified semid, and check more usage --help
ipcrm -s semid


#5) Delete all semid semaphore methods
ipcrm  -asem

5. Here, in the process of finding semaphore resource leakage, in order to facilitate real-time viewing of semaphore information, the semaphore output is written into the script and printed circularly

#ipcs.sh
echo “ipcs -s loop”

while [ 1 ]
do
	sleep 1
	ipcs -s
done

6. Note: the final problem here is to see why the semaphore in the code exceeds the limit. Normally, the semaphore will not exceed the system limit.

[Solved] Nvml compilation official use case error: collect2: error: ld returned 1 exit status

Question

When running the example of nvml, an error is reported:

/tmp/tmpxft_00001d31_00000000-4_gpu_monitor.o: In the function ‘main’:
gpu_monitor.c:(.text+0x77): undefined reference to ‘nvmlInit_v2’
gpu_monitor.c:(.text+0x93): undefined reference to ‘nvmlErrorString’
gpu_monitor.c:(.text+0xcd): undefined reference to ‘nvmlDeviceGetCount_v2’
gpu_monitor.c:(.text+0xe9): undefined reference to ‘nvmlErrorString’
gpu_monitor.c:(.text+0x15e): Undefined reference to ‘nvmlDeviceGetHandleByIndex_v2’
gpu_monitor.c:(.text+0x17a): undefined reference to ‘nvmlErrorString’
gpu_monitor.c:(.text+0x1b4): undefined reference to ‘nvmlDeviceGetName’
gpu_monitor.c:(.text+0x1d0): undefined reference to ‘nvmlErrorString’
gpu_monitor.c:(.text+0x208): Undefined reference to ‘nvmlDeviceGetPciInfo_v3’
gpu_monitor.c:(.text+0x224): undefined reference to ‘nvmlErrorString’
gpu_monitor.c:(.text+0x282): undefined reference to ‘nvmlDeviceGetComputeMode’
gpu_monitor.c:(.text+0x2b6): undefined reference to ‘nvmlErrorString’
gpu_monitor.c:(.text+0x318): undefined reference to ‘nvmlDeviceSetComputeMode’
gpu_monitor.c:(.text+0x334): undefined reference to ‘nvmlErrorString’
gpu_monitor.c:(.text+0x379): undefined reference to ‘nvmlErrorString’
gpu_monitor.c:(.text+0x3ce): undefined reference to ‘nvmlDeviceSetComputeMode’
gpu_monitor.c:(.text+0x3ea): undefined reference to ‘nvmlErrorString’
gpu_monitor.c:(.text+0x423): Undefined reference to ‘nvmlDeviceGetPowerUsage’
gpu_monitor.c:(.text+0x43f): undefined reference to ‘nvmlErrorString’
gpu_monitor.c:(.text+0x4a4): undefined reference to ‘nvmlShutdown’
gpu_monitor.c:(.text+0x4c0): undefined reference to ‘nvmlErrorString’
collect2: error: ld returned 1 exit status

Solution:

At the beginning, the above error occurs when compiling with the command nvcc – O example.C example.
compile successfully with the command nvcc – I – L/usr/lib – lnvidia ml example.C – O example