bash

script to read a file with IP addresses and login

梦想与她 提交于 2021-02-11 18:14:43
问题 I have a file named "host.txt" with listing IP addresses of two systems. ~] cat hosts.txt 10.1.1.10 10.1.1.20 Using below script I am trying to login to each system, check status of a service and print the output of each system. The script prompts to login, however does not continue to execute the /opt/agent.sh status command. Can someone please help fix this script? #!/bin/bash for HOST in `cat hosts.txt` do ssh root@$HOST STATUS=`/opt/agent.sh status | awk 'NR==1{print $3 $4}'` echo $STATUS

egrep and grep difference with dollar

﹥>﹥吖頭↗ 提交于 2021-02-11 17:24:34
问题 I'm having touble understanding the different behaviors of grep end egrep when using \$ in a pattern. To be more specific: grep "\$this->db" file # works egrep "\$this->db" file # does not work egrep "\\$this->db" file # works Can some one tell me why or link some explanation? Thank you very much. 回答1: The backslash is being eaten by the shell's escape processing, so in the first two cases the regexp is just $this->db . The difference is that grep treats a $ that isn't at the end of the

Bash: conditional based on specific exit code of command

纵然是瞬间 提交于 2021-02-11 15:59:32
问题 This question is a follow-up to Bash conditional based on exit code of command . I understand, and have made use of the accepted answer to that question: $ cat ./txt foo bar baz $ if ! grep -Fx bax txt &>/dev/null; then echo "not found"; fi not found $ But I can't figure out the syntax to pull off a seemingly simple twist to the premise: how can I write a conditional for a specific exit code of a command? This post pointed out that grep might fail with error code > 1; so I wanted to write the

from: cant read /varmail/ctypes when called

心已入冬 提交于 2021-02-11 15:45:19
问题 I am trying to implement some object detection in a project of mine using darknet.py. from my terminal I am able to run python3 darknet.py and get my results all fine. But when I have tried to include it in my own program I am getting several errors; from: cant read /var/mail/ctypes import im6.q16: not authorized math @error/constitute.c/writeimage/1037 I am not sure how to proceed. I have made sure darknet.py starts with #!/usr/bin/ env python3 as does my program, i am trying to run it with

from: cant read /varmail/ctypes when called

心已入冬 提交于 2021-02-11 15:44:28
问题 I am trying to implement some object detection in a project of mine using darknet.py. from my terminal I am able to run python3 darknet.py and get my results all fine. But when I have tried to include it in my own program I am getting several errors; from: cant read /var/mail/ctypes import im6.q16: not authorized math @error/constitute.c/writeimage/1037 I am not sure how to proceed. I have made sure darknet.py starts with #!/usr/bin/ env python3 as does my program, i am trying to run it with

How to exclude some files from the loop in shell script [duplicate]

人走茶凉 提交于 2021-02-11 15:37:54
问题 This question already has answers here : for-loop for every folder in a directory, excluding some of them (5 answers) Closed 12 months ago . #! /bin/sh for file in $Files/*.txt; do chmod 777 $file done It will give permission 777 to all .txt files but I've 7 other .txt file for which I don't want to give 777 permission. How can I do that? 回答1: you can add a conditional check as below. As there's no clear attribute differentiating the files you want to exclude, you'd need to specifically check

How can I run a shell script via SSH such that the environment of the remote computer is similar to that of the local computer?

早过忘川 提交于 2021-02-11 15:27:22
问题 I welcome rephrasing of my question, because I'm not sure exactly what the problem is called. I am trying to run a shell script via SSH using a command of the following form: ssh -o StrictHostKeyChecking=no lxplus0035 "cd ~/test; bash script1.sh" When I do this, the complex script script1.sh breaks with many syntax errors, operand errors and other errors. An example is as follows: stty: standard input: Invalid argument The script works fine when run directly, not via SSH, in the local system

How can I run a shell script via SSH such that the environment of the remote computer is similar to that of the local computer?

妖精的绣舞 提交于 2021-02-11 15:26:24
问题 I welcome rephrasing of my question, because I'm not sure exactly what the problem is called. I am trying to run a shell script via SSH using a command of the following form: ssh -o StrictHostKeyChecking=no lxplus0035 "cd ~/test; bash script1.sh" When I do this, the complex script script1.sh breaks with many syntax errors, operand errors and other errors. An example is as follows: stty: standard input: Invalid argument The script works fine when run directly, not via SSH, in the local system

bash grep 'random matching' string

余生颓废 提交于 2021-02-11 15:19:32
问题 Is there a way to grab a 'random matching' string via bash from a text file? I am currently grabbing a download link via bash, curl & grep from a online text file. Example: DOWNLOADSTRING="$(curl -o - "http://example.com/folder/downloadlinks.txt" | grep "$VARIABLE")" from online text file which contains http://alphaserver.com/files/apple.zip http://alphaserver.com/files/banana.zip where $VARIABLE is something the user selected. Works great, but i wanted to add some mirrors to the text file.

Different behaviors with 2 different Websocket APIs but same request

﹥>﹥吖頭↗ 提交于 2021-02-11 14:54:49
问题 I am trying to communicate with my Samsung smart TV and I found on internet that it works with Websocket. There is some Samsung smart TV API on GitHub but they didn't work with my TV. Apparently, I have a not so common TV model. Currently, I am stuck because I don't have the same behavior when I am doing (or trying to do) the same thing with two different Websocket APIs. WSCAT $ wscat -c wss://192.168.1.20:8002/api/v2/channels/samsung.remote.control?name=dGVzdA== -n --no-color Connected