shell

How to use the output of the shell command in expect script's send

笑着哭i 提交于 2021-01-29 13:49:21
问题 I have a expect script written to perform a login operation. The login requires the 2fa code, this code can be obtained by executing the shell command 2fa my_login . Now how do I execute the 2fa command and pass it's output to the send of my script? I need to do something like send -- "$(2fa my_login)" . The output of the $(2fa my_login) should be passed to the send. My script #!/usr/bin/expect -f set timeout -1 spawn /home/local/apps/forticlientsslvpn/64bit/forticlientsslvpn_cli --server vpn

Get comment tag from XML attribute with Bash

我的梦境 提交于 2021-01-29 13:13:52
问题 I understand how to retrieve XML content within regular nodes, but I would like to understand how to retrieve content within a comment tag in XML using Bash. For example, consider the below XML snippet: <ParentTag1><!--This comment is associated to ParentTag1 --> <ChildTag1>ChildTag1Blah</ChildTag1><!-- ChildTag1 comment--> <ChildTag2><!-- ChildTag2 comment --> <GrandchildTag1>GrandchildTag1Blah</GrandchildTag1><!-- GrandchildTag1 comment--> <GrandchildTag2>GrandchildTag2Blah</GrandchildTag2>

Script to check if ssh connection is success

☆樱花仙子☆ 提交于 2021-01-29 11:11:13
问题 I have 100 servers. From the first server, i want to check if ssh connection from this first server to other servers is OK or not. If OK, then it would ouput OK, if not, it would output Failed. I did some setup before with hostname and key pair, so basically i just enter: ssh name-server Then i would know the result. For example Failed case: [centos@tony]$ ssh server1 Last login: Thu Aug 9 17:01:21 2018 from 172.21.11.5 Connection to server1 closed. OK case: [centos@tony]$ ssh server1 Last

Get available space on mounted device with folder with whitespaces using bash

时光怂恿深爱的人放手 提交于 2021-01-29 10:50:58
问题 I try to get Available space on mounted disk: df /tmp/mount/0dfShksftN | tail -1 | awk '{print $4}' It works fine but not in cases when Filesystem param has folder name with spaces. I found solution for getting Filesystem and Mount point values in this case: df -P "/mnt/MOUNT WITH SPACES/path/to/file/filename.txt" | awk 'BEGIN {FS="[ ]*[0-9]+%?[ ]+"}; NR==2 {print $NF}' But can't find solution for Available field value. I could take the entire string and parse by myself but maybe there is a

Bash conditional based on exit code of command

二次信任 提交于 2021-01-29 10:18:21
问题 In Bash, I would like an if statement which is based of the exit code of running a command. For example: #!/bin/bash if [ ./success.sh ]; then echo "First: success!" else echo "First: failure!" fi if [ ./failure.sh ]; then echo "Second: success!" else echo "Second: failure!" fi success.sh #!/bin/bash exit 0 failure.sh #!/bin/bash exit 1 This should print out: First: success! Second: failure! How would I achieve this? Thanks! 回答1: Just remove the brackets: #!/bin/bash if ./success.sh; then

Whenever I run a program in Python Shell I get a line that says RESTART: C:\… $

别来无恙 提交于 2021-01-29 10:05:29
问题 Whenever I run a program in Python Shell I get a line that says RESTART: C:\... $ . Restarting the program, using programs that did not have this issue in the past etc. do not seem to do anything. Thanks in advance for any advice! What is causing this? 回答1: That line means that the .py file has been executed in the python shell. It's a log statement to explicitly declare that your namespace is being cleared and the file is going to be ran fresh again. In simple words: The IDLE internally

Find files recursively and rename based on their full path

隐身守侯 提交于 2021-01-29 09:52:17
问题 I'm looking to search for files of a specific name, modify the name to the full path and then copy the results to another folder. Is it possible to update each find result with the full path as the file name; i.e. ./folder/subfolder/my-file.csv becomes folder_subfolder_my-file.csv I am listing the files using the following and would like to script it. find . -name my-file.csv -exec ls {} \; 回答1: Since you're using bash, you can take advantage of globstar and use a for loop: shopt -s globstar

Problem creating multiple child processes

可紊 提交于 2021-01-29 09:42:03
问题 Im new at process creation etc..so probably a basic question. Im creating a fixed number of child processes, each doing nothing but printing their pid. The problem is in the output that i get. Have a look: int main(){ pid_t pid=0; int i=0,status=0; for(i=0;i<3;i++){ pid=fork(); switch(pid){ case 0:{ //Child printf("\nChild pid: %d",getpid()); exit(0); break; } case -1: {//Error printf("Error occured in fork"); exit(1); break; } default:{ printf("\nParent id: %d",getpid()); printf("\nIts child

Makefile variable value not available during ifeq

痞子三分冷 提交于 2021-01-29 09:06:24
问题 I have the following Makefile SHELL=/bin/bash .SHELLFLAGS=-O extglob -o errexit -o pipefail -o nounset -c .PHONY: testing define getFileContents $(shell cat ./test.txt) endef TEST_STATIC=dummy deploy: $(eval TEST=$(getFileContents)) @echo "$(TEST)" ifeq ($(TEST),dummy) @echo "$(TEST) is FAILED" else @echo "$(TEST) is PASS" endif ifneq (,$(findstring dummy,$(TEST))) @echo "$(TEST) is FAILED" else @echo "$(TEST) is PASS" endif ifeq ($(TEST_STATIC),dummy) @echo "$(TEST) is FAILED" else @echo "$

How to make a Makefile call another Makefile rules?

你离开我真会死。 提交于 2021-01-29 08:31:51
问题 As the title says: How can I call a rule in another Makefile from a Makefile? For example: I have a folder named "folder1" that has a makefile1 and another folder named "folder2" which has another makefile2 . Now I want to call a rule in makefile1 from make in "folder2". How can I do that? 来源: https://stackoverflow.com/questions/53569376/how-to-make-a-makefile-call-another-makefile-rules