unix

Execute script over SSH and get output? [duplicate]

 ̄綄美尐妖づ 提交于 2020-01-15 07:42:06
问题 This question already has answers here : Running a Bash script over ssh (5 answers) Closed 3 years ago . I am trying to execute a command in a remote machine and get the output. I have tried implementing below shell script but unable to get the content. #!/bin/bash out=$(ssh huser@$source << EOF while IFS= read -r line do echo 'Data : ' $line done < "data.txt" EOF ) echo $out Output: Data : Data : Data : I could see the "Data :" is printed 3 times because the file "data.txt" has 3 lines of

Different versions of UNIX sort handle case differently

瘦欲@ 提交于 2020-01-15 07:35:55
问题 I am using sort both on Mac OS X and Ubuntu Linux, and I am observing a different handling of uppercase/lowercase comparisons. On Mac OS X, sort (GNU coreutils) 5.93 gives the behavior I expect: $ sort <<EOF > Aa > aa > Ab > ab > EOF Aa Ab aa ab On Ubuntu, sort (GNU coreutils) 8.5 seems to ignore case: $ sort <<EOF > Aa > aa > Ab > ab > EOF aa Aa ab Ab Is there a way to disable this behavior? I need case-sensitive sort. I tried to change the LOCALE to C and nothing changed. Alternatively, is

Bash Script: Send files to SFTP using Expect

╄→尐↘猪︶ㄣ 提交于 2020-01-15 07:30:27
问题 I have to send few gzipped files from local server to SFTP server. My Server Info Distributor ID: Ubuntu Description: Ubuntu 12.04.4 LTS Release: 12.04 Codename: precise Created a bash script and could able to send files to sftp, but i want to send email if transfer is successful. #!/bin/bash HOST=hostname.domain PORT=22 USER=username PASSWORD=password SOURCE_FILE=path/filename TARGET_DIR=PATH /usr/bin/expect<<EOD spawn /usr/bin/sftp -o Port=$PORT $USER@$HOST expect "password:" send "

How do I set file permissions when opening a file in C++?

ε祈祈猫儿з 提交于 2020-01-15 07:27:26
问题 In C++, I want to open a file and set its permission, but I failed. Below is my program: string filename="test.cnf"; ofstream ofile; ofile.open(filename.c_str(),O_RDONLY); ofile.close() But I get the following error: error: invalid conversion from 'int' to 'std::_Ios_Openmode' error: initializing argument 2 of 'void std::basic_ofstream<_CharT, _Traits>::open(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]' How to set the permission of the file to such

How to merge separated fields in rows into one based on common fields in AWK / UNIX

笑着哭i 提交于 2020-01-15 06:38:28
问题 I am still just a new user to UNIX and especially to AWK. I am having the problem to merge rows based on first 2 columns values. My original data from a file as below: Original data content ======================== ID1 ID2 Field1 Field2 1 1 11F1 11F2 1 2 12F1 12F2 2 1 21F1 21F2 2 2 22F1 22F2 ID1 ID2 Field3 Field4 1 1 11F3 11F4 1 2 12F3 12F4 2 1 21F3 21F4 2 2 22F3 22F4 ID1 ID2 Field5 Field6 1 1 11F5 11F6 1 2 12F5 12F6 2 1 21F5 21F6 2 2 22F5 22F6 As you noticed, columns are split into different

Line buffered reading in Perl

非 Y 不嫁゛ 提交于 2020-01-15 05:31:10
问题 I have a perl script, say "process_output.pl" which is used in the following context: long_running_command | "process_output.pl" The process_output script, needs to be like the unix "tee" command, which dumps output of "long_running_command" to the terminal as it gets generated, and in addition captures output to a text file, and at the end of "long_running_command", forks another process with the text file as an input. The behavior I am currently seeing is that, the output of "long_running

How to separate the filenames and contents matching a particular pattern in various separate files

旧时模样 提交于 2020-01-15 05:24:52
问题 I am trying to segregate filenames matching a particular into a separate file and its contents into different files matching particular patterns.I have the filenames with special characters included like '|' I tried using grep command. Grep Ril and Grep -H to print the filenames,but it is not working. #!bin/bash cd home/test let "x = 1" for file in $(find home/test/* -type f -name "*.txt") ; do var=$(echo "${x}|fill|${file##*/}") echo "${var}" | grep -n "*|fill|*.txt" >header.txt myvar=$(sed

Automatically release mutex on crashes in Unix

末鹿安然 提交于 2020-01-15 04:25:07
问题 I have two programs interacting via a shared memory segment. When using the segment for read or write, they hold a lock. Should either of them crash (get killed, typically - possibly with something untrappable) in a critical section, I would like them to release the lock so that the shmem isn't locked out completely. Other questions point the way to the answer in Windows, Java, etc. but how do you do it in Unix (and specifically Linux)? (I'm not attached to the pthreads mutex functions; SysV

Create hidden, non visible window in X?

拈花ヽ惹草 提交于 2020-01-15 04:24:27
问题 Is it possible in X to create a window that is not visible? I looked at the XCreateSimpleWindow API but did not find any attributes to make it hidden. Is there a way? Thanks 回答1: You may be looking for an InputOnly window. You can specify the class as InputOnly when using XCreateWindow. 来源: https://stackoverflow.com/questions/7856768/create-hidden-non-visible-window-in-x

Automatically release mutex on crashes in Unix

a 夏天 提交于 2020-01-15 04:24:26
问题 I have two programs interacting via a shared memory segment. When using the segment for read or write, they hold a lock. Should either of them crash (get killed, typically - possibly with something untrappable) in a critical section, I would like them to release the lock so that the shmem isn't locked out completely. Other questions point the way to the answer in Windows, Java, etc. but how do you do it in Unix (and specifically Linux)? (I'm not attached to the pthreads mutex functions; SysV