linux,windows,perl,process,stdin
This isn't a Windows verus Linux thing. You simply picked two awful examples. type con reads from the console, not from STDIN. This can be seen using type con <nul. cat is extremely unusual. Buffering, on either system, is completely up to the individual application, but almost all applications work...
Try this to create a string variable n, with no leading whitespace (thanks @011c): n="10.0.0.135.527" wget http://infamvn:8081/nexus/content/groups/LDM_REPO_LIN64/com/infa/com.infa.products.ldm.ingestion.server.scala/"$n"-SNAPSHOT/com.infa.products.ldm.ingestion.server.scala-"$n"-20150622.210643-1-sources.jar ...
Here's a sed version: /^Host_Alias/{ # whenever we match Host_Alias at line start : /\\$/{N;b} # if backslash, append next line and repeat s/$/,host25/ # add the new host to end of line } If you need to add your new host to just one of the host aliases, adjust...
This awk program will print the modified header and modify the output to contain the sums and their division: awk 'BEGIN {FS=OFS=";"} (NR==1) {$10="results/time"; print $0} (NR>1 && NF) {sum8[$10]+=$8; sum9[$10]+=$9; other[$10]=$0} END {for (i in sum8) {$0=other[i]; $8=sum8[i]; $9=sum9[i]; $10=(sum9[i]?sum8[i]/sum9[i]:"NaN"); print}}' which gives: Date;dbms;type;description;W;D;S;results;time;results/time Mon Jun 15 14:22:20 CEST...
You don't need the -s flag to determine the uptime. If you do something like this you have the time the server is running: $tmp = explode(' ', exec('uptime')); $uptime = $tmp[2]; // something like 2:14 (hh:mm) nb: an alternative would be to use the who -b command, which will...
You can achieve that by using the env utility: timeout 10 /usr/bin/env LD_LIBRARY_PATH=/path/to/mod/libc/ cp a b Env will set the environment variable and exec the other utility with that environment....
Escape / with \: sed -i 's/mrm.fr.mycompany.com/10.70.89.40:8081\/artifactory/' config.xml Or use this: sed -i 's|mrm.fr.mycompany.com|10.70.89.40:8081/artifactory|' config.xml ...
python,linux,command-line,tcp,pipe
Would pipes and stdin work? Here is a similar question just asked a couple minutes ago. Reading from linux command line with Python...
Through awk, $ awk '$5!="99999"{sum+=$5}END{print sum}' file 227.5 Explanation: $5!="99999" if 5th column does not contain 99999, then do {sum+=$5} adding the value of 5th column to the variable sum. Likewise it keeps adding the value of 5th column when awk see's the record which satisfies the given condition. Finally...
It seems you need to add a catch-all server block: server { listen 80 default_server; server_name ""; return 444; } The 444 status code will close the connection without sending a response....
This reads each number from the input file, and outputs the correctly modified output to each output file. while IFS='' read -r number; do printf "%d\n" $((number + 5)) >&3 printf "%d\n" $((number * 5)) >&4 done < input.txt 3> first.txt 4> second.txt ...
To find which symbols made your elf non-PIC/PIE (Position Independent Code/Executable), use scanelf from pax-utils package (on ubuntu, install it with sudo apt-get install pax-utils): $ scanelf -qT /usr/local/lib/libluajit-5.1.so.2.1.0 | head -n 3 libluajit-5.1.so.2.1.0: buf_grow [0x7694] in (optimized out: previous lj_BC_MODVN) [0x7600] libluajit-5.1.so.2.1.0: buf_grow [0x769C] in (optimized out: previous lj_BC_MODVN)...
Instead of using xlabel and ylabel, you may want to go with set label. For example, #!/usr/local/bin/gnuplot datafile='tmp.dat' # file to plot set xlabel " " # no x-label set ylabel " " # no y-label # assuming all plots have same x and y range set xrange [-2:2] set...
My attempt: #! /bin/bash if [ $# -gt 2 -o $# -lt 1 -o ! -f "$1" ]; then echo "Usage: ${0##*/} <filename> [<split size in M>]" >&2 exit 1 fi bsize=${2:-100} bucket=$( echo $bsize '* 1024 * 1024' | bc ) size=$( stat -c '%s' "$1" ) chunks=$( echo...
The errors, as awk helpfully (though verbosely) tells you awk: cmd. line:1: /^e/ {i++; rx[i]=$2}; tx[i]=$10}; END{printf(" down: %.2f Mbps, up: %.2f Mbps", ((rx[2]-rx[1])/1024/1024)), ((tx[2]-tx[1])/1024/1024))} awk: cmd. line:1: ^ syntax error awk: cmd. line:1: each rule must have a pattern or an action part awk: cmd. line:1: /^e/ {i++; rx[i]=$2};...
#!/bin/bash declare -A SArray SArray[a]="a" SArray[b]="b" read index if test "${SArray["$index"]+isset}"; then echo "index $index exists for SArray" else echo "no index $index for SArray" fi ...
I found the discussion in Valgrind mail list when someone had the same problem. The issue was that the kernel have been patched with PaX patches, one of which doesn't allow to look at the /proc/pid/maps. The quote about the patch from wikipedia The second and third classes of attacks...
It seems like you're looking for an indirect variable reference. Your $cmd variable points to the variable $Apr and you want to use the value of $Apr. Here's how you can do this (just the relevant lines): cmd=$(date | awk '{print $2}') eval month=\$$cmd dat=$(ls -ltr | grep $month |...
awk cannot look ahead so you'll have to save the lines. awk 'NR>2{if(z!="")print z;z=y;y=x;x=$0}' file Practically zero memory overhead...
Have you checked any potential opcode caches and their settings? In the past I have had some issues there, eg not detecting changed files. Specifically, this situation can and will happen if opcache.use_cwd setting is set to zero. opcache.use_cwd boolean If enabled, OPcache appends the current working directory to the...
The possible range of virtual addresses is processor and kernel and ABI specific. But I strongly advise against coding some tricks related to some bits in addresses and pointers (since your code might work on some processors, but not on others). These days, some * x86-64 processors apparently use only...
linux,shell,command-line,awk,sed
Almost same as the other answer, but printing 0 instead of blank. AMD$ awk -F, 'NR>1{a[$2]+=$3;b[$2]++} END{for(i in a)print i, a[i], b[i]}' File pear 1 1 apple 2 3 orange 0 1 peach 0 1 Taking , as field seperator. For all lines except the first, update array a. i.e...
You have not linked the executable against several libraries that are required by the program Try using this: g++ -lpthread `pkg-config opencv --libs` -I/usr/local/include/ -lraspicam -lraspicam_cv -L/opt/vc/lib -lmmal -lmmal_core -lmmal_util -I/usr/include -lwiringPi test3.cpp -o test3 ...
In Signal handler there are only a very limited number of syscalls allowed. see man 7 signal http://man7.org/linux/man-pages/man7/signal.7.html My Suggestion is, to be on the safe side, the so called "self pipe trick". http://man7.org/tlpi/code/online/diff/altio/self_pipe.c.html You could start a thread which runs a select Loop on the self pipe and call...
c,linux,memory,stack,portability
Q 1. why is ch empty even after fread() assignment? (Most probably) because fread() failed. See the detailed answer below. Q 2.Is this a portability issue between Solaris and Linux? No, there is a possible issue with your code itself, which is correctly reported by valgrind. I cannot quite...
Timeout through the API is definitely supported. Maybe 100ms on your Linux box is too much? Can you try with a smaller timeout? If it still fails, could you file a bug report with a short, self-contained, reproducing test case? Thanks!...
linux,haskell,make,ghc,theorem-proving
Looks like paradox was written for a rather old version of GHC. You can fix all these "Could not find module" errors by using GHC version 7.8 or older and setting GHC = ghc -hide-package base -package haskell98 in the Makefile, though you will likely encounter more errors after that....
Please save following awk script as awk.src: function date_str(val) { Y = substr(val,0,4); M = substr(val,5,2); D = substr(val,7,2); date = sprintf("%s-%s-%s",Y,M,D); return date; } function time_str(val) { h = substr(val,9,2); m = substr(val,11,2); s = substr(val,13,2); time = sprintf("%s:%s:%s",h,m,s); return time; } BEGIN { FS="|" } # ## MAIN...
linux,linux-kernel,kernel,linux-device-driver,system-calls
The ret_from_syscall symbol will be in architecture-specific assembly code (it does not exist for all architectures). I would look in arch/XXX/kernel/entry.S. It's not actually a function. It is part of the assembly code that handles the transition from user-space into kernel-space for a system call. It's simply a label to...
Do you want to remove redis old package you can use yum remove command as below. yum remove redis then check it still available as below rpm -qi redis and also check files rpm -ql redis if its there you can remove as below. rpm -e redis (or you can...
linux,windows,sockets,network-programming,raspberry-pi
InputStream input = client.getInputStream(); BufferedReader in = new BufferedReader(new InputStreamReader(input)); Your problem is here. You can't use multiple inputs on a socket when one or more of them is buffered. The buffered input stream/reader will read-ahead and 'steal' data from the other stream. You need to change your protocol so...
Using Parameter Expansion: $ var="fooo_barrrr" $ echo ${var#*_} barrrr To change the var itself, var=${var#*_}. Note this removes up to the first _: $ var="fooo_barrr_r" $ echo ${var#*_} barrr_r If you wanted to remove up to the last one, you would need to use ## instead: $ var="fooo_barrr_r" $ echo...
You can create an alias: alias php="php55" Now if you type php it uses php55...
It looks like you're missing zlib; you'll want to install it: apt-get install zlib1g-dev I also suggest reading over the README and confirming you have all other dependencies met: https://github.com/dccmx/mysqldb/blob/master/README Also, I suggest using mysqlclient over MySQLdb as its a fork of MySQLdb and what Django recommends....
This is usually a sign that you should update your mono. Older mono versions have issues with their unzip implementation
The following cron job will run Rscript scriptSecos.R from the path /home/script2, once a day, at 0:00 (midnight). 0 0 * * * cd /home/script2; Rscript scriptSecos.R >/dev/null 2>&1 If you want to save the output of the script to a file, change >/dev/null with >/path/to/file. You can copy and...
try this: cat path_to_your_log_file|awk '{split($2,res,":");var=res[1]":"res[2]":"res[3];counter[var]+=$1}END{for(i in counter){print counter[i],i}}' ...
As indicated in the comments, you need to provide "something" to your while loop. The while construct is written in a way that will execute with a condition; if a file is given, it will proceed until the read exhausts. #!/bin/bash file=Sheetone.txt while IFS= read -r line do echo sh...
php,linux,apache,logging,permissions
I'd simply set its owner to apache user. This will give you the name of apache user : ps aux | grep httpd In my case (CentOS), it's 'apache' but sometimes it's 'www-data'... chown apache:apache /var/log/httpd/php_errors.log chmod 600 /var/log/httpd/php_errors.log ...
The instruction is Add "contrib" and "non-free" components to /etc/apt/sources.list, for example I.e., you're supposed to add that line to the given file with a text editor. You are not supposed to execute it on a command line....
You can limit the number of file descriptors a process can open under Linux using ulimit. Executing ulimit -n 3 before running your C program should make it an error to open any more files, since stdin, stdout, and stderr take up the first 3 descriptors. An example: $ ulimit...
c,linux,sockets,udp,thread-safety
Are the C functions recvfrom and sendto mutually exclusive? No. They can both be executed by different threads at the same time. sendto() doesn't wait for recvfrom() to read the data. It would place the data into the socket's buffer and return. Multiple sendto() may block for the previous...
I think what you are looking for is umask umask 0022 umask -p umask -S You will need to modify your default /etc/profile in order to make this permanent. umask 0022will on creation give directories chmod 755 and files chmod 644 which is the recommended permissions for the www folder...
python,linux,django,web,frameworks
You can use the __range field lookup: start = datetime.date.today() end = start + datetime.timedelta(days=1) Model.objects.filter(datetime__range=(start, end)) ...
1) change my.conf (whatever your mysql conf file is called). And set bind-address to 0.0.0.0 as it is prob 127.0.0.1 2) stop/restart mysql daemon Connections now are not limited to those from localhost. The default is localhost for obvious security reason until dev guy tweaks it 3) grants with flush...
It seems the process you control is changing terminal settings. These are bypassing stderr and stdout - for good reasons. E.g. ssh itself needs this to ask users for passwords even when it's output is being redirected. A way to solve this could be to use the python-module pexpect (it's...
The problem is, you don't have debug info for the ptr type, so gdb treats it as integer. You can examine its real contents using: (gdb) x/a &ptr 0x600124 <ptr>: 0x7fffffffe950 (gdb) p/a $rsp $3 = 0x7fffffffe950 Of course I have a different value for rsp than you, but you...
array_name=(value1 ... valuen) This is how to initializes an array in bash only. When you execute ./example.sh, the shebang line #!/bin/bash tells the system to use bash to execute. However, when you execute sh example.sh, sh is used to execute. In many Unix systems (like Linux), sh is equivalent to...
c,linux,kernel,linux-device-driver
Often when working close to the hardware or when trying to control the size/format of a data structure you need to have precise control of the size of your integers. As for u8 vs uint8_t, this is simply because Linux predated <stdint.h> being available in C, which is technically a...
When sending, you're assuming the data is null terminated: if((send(sockfd, buf, strlen(buf), 0)) < 0){ You should use the count actually returned by the read method, and you shouldn't use fgets() for that purpose. Your receive loop makes no sense. You're calling recv() several times and testing the result...
Turns out the code wasn't invalid (had to correct some quoting issues) but that the folder was corrupt when i tried to use it in the bash script. Here is the working code with the correct double quotes around the directory variables. #!/bin/bash #file location XMLDIR='/home/amoore19/XML/00581-001/scores' NEWXML='/home/amoore19/XML/00581-001' #this gives me...
anubhava's solution is excellent if, as they do in your example, the extensions sort into the right order. For the more general case, where sorting cannot be relied upon, we can specify the argument order explicitly: for f in *.ext1 do program "$f" "${f%.ext1}.ext2" done This will work even if...
Had same issue now, just a minute ago. But I am using a combination of Casperjs with Slimerjs engine (Casperjs is a great tool for working with your slimerjs and phantomjs scripts, in a friendlier enviroment programming). The working php script: <?php putenv("PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs"); putenv("CASPERJS_EXECUTABLE=/usr/local/bin/casperjs"); putenv("SLIMERJS_EXECUTABLE=/usr/local/bin/slimerjs"); putenv("DYLD_LIBRARY_PATH"); echo passthru('/usr/bin/xvfb-run /usr/local/bin/casperjs --ssl-protocol=any...
You can use globbing: head -n 10 *.cpp > all_headers.txt The above command exports the first 10 lines of all cpp files in a folder into all_headers.txt. According to Aereaux's comment you should also use the -q option of head since otherwise head would print the file name before the...
linux,vagrant,backup,virtual-machine,sync
Vagrant doesn't inherently support this, since it's intended audience is really development environments. It seems like you're looking for something more like what VMWare vSphere does.
Do you want see route for ether0, you can use below command ip -o route show dev ether0 or ip route show | grep ether0 or route -n | grep ether0 or netstat -nr | grep ether0 To see NIC for ether0, you can use ifconfig command and Gateway NIC...
Try doing it using find and for: for file in `find . -type f -name "*.sh"`; do sh $file; done Use can also store it in array and do it: array=($(find . -type f -name "*.sh")) for file in ${array[@]};do sh $file; done ...
Try this: find . -mmin +35 -or -mmin -25 find supports several logical operators (-and, -or, -not). See the OPERATORS section of the man pages for more details. ==================== EDIT: In response to the question about processing the two matches differently, I do not know of a way to do...
find $DELDIR -type f | xargs cp /dev/null where $DELDIR is the name of the directory to start in. The -type f option targets only files, not directories. And of course xargs just finishes off cp /dev/null with the file names from each line of find output....
You can use below snippet to run a command in shell. So use this same method to invoke the specific ls command using ssh in all supervisor nodes (from external node like nimbus). public String executeCommand(String command) { StringBuffer output = new StringBuffer(); Process p; try { p = Runtime.getRuntime().exec(command);...
linux,git,githooks,git-post-receive
The hook file is incorrectly named post-reveive.
Change the order of your struct like this struct user_info { char name[16]; uid_t uid; }; It will override as your expect....
The output from set -x uses single quotes. So the outer double quotes were replaced with single quotes but you can't escape single quotes inside a single quoted string so when it then replaced the inner double quotes it needed, instead, to replace them with '\'' which ends the single...
as you see, in Edit1, you (make) try to run JavaScriptCore-4.0.gir instead of compile it with g-ir-compiler; I tried on my pc and my command is: cd /home/davide/src/webkitgtk-2.8.3/build/Source/JavaScriptCore && \ /usr/bin/g-ir-compiler /home/davide/src/webkitgtk-2.8.3/build/JavaScriptCore-4.0.gir \ -o /home/davide/src/webkitgtk-2.8.3/build/JavaScriptCore-4.0.typelib as a workaround, you cand edit: build/Source/JavaScriptCore/CMakeFiles/JavascriptCore-4-gir.dir/build here's the lines on my file (the last...
linux,apache,.htaccess,prestashop,prestashop-1.6
There are a couple of things I see just looking at the configuration. You have your vhost config named etc/apache2/sites-enabled/prestashop.config But that is not the file type that is being included in the apache.conf file. # Include the virtual host configurations: IncludeOptional sites-enabled/*.conf Your apache setup looks for .conf files...
In x="1 2 3" for i in $x what you are doing is for i in 1 2 3:. But in second case doing xm=`cat $x` ym=`cat $y` This might lead to error saying No such file or directory is the echo $x and echo $y file does not exit....
.* is greedy: it matches all possible characters. This way, even sed 's/<?php.*//' file will also delete all the content in your file. To prevent this greediness of .*, say "everything but a ?" -> [^?]*: sed 's/<?php[^?]*?><?php[^?]*?>//' file Test $ cat a <?php echo 'first' ?><?php echo 'second' ?><?php...
Using bash -c: newvar="$(bash -c "echo $var")" Using eval: newvar="$(eval "echo $var")" Example: #!/bin/bash var='$PATH' echo "$var" #This will show that $var contains the string $PATH literally #Using bash -c newvar="$(bash -c "echo "$var"")" echo "$newvar" #using eval newvar="$(eval "echo "$var"")" echo "$newvar" It will print the environment variable paths...
python,linux,shell,command-line
You need to read stdin from the python script. import sys data = sys.stdin.read() print 'Data from stdin -', data Sample run - $ date | python test.py Data from stdin - Wed Jun 17 11:59:43 PDT 2015 ...
linux,shell,sed,grep,pattern-matching
The -v option to grep inverts the search, reporting only the lines that don't match the pattern. Since you know how to use grep to find the lines to be deleted, using grep -v and the same pattern will give you all the lines to be kept. You can write...
Well, it appears this is a long standing bug in the older File API. I've solved all my problems - with no additional configs of any kind - by switching to the newer java.nio package.
regex,linux,shell,unix,replace
You can do it using awk as: awk '/\[x/{f=1} {if(f)printf "%s",$0; else print $0;} /y\]/{print ""; f=0}' Output: [x data1 data2 data3 data4 y] [a data5 data 6 data7 data 8 b> [x data y] You can also simplify to: awk '/\[x/,/y\]/{ORS=""; if(/y\]/) ORS="\n";}{print}' Output: [x data1 data2 data3 data4...
wget expect can be tricky to work with so I'd prefer to use GNU Wget as an alternative. The following should work as long as you don’t have any spaces in any of the arguments. for v in "${files_to_download[@]}" do ftp_file="${v}.bz2" wget --user=${USER} --password=${PASSWD} ${HOST}/${ftp_file} done Request multiple resources using...
Yes, use the -S switch which reads the password from STDIN: $echo <password> | sudo -S <command> Exposing your password is generally bad idea search for something that can protect / hide it. In the past I've used Jenkins plugins to do this while executing the scripts regularly....
linux,bash,shell,command-line,tee
Hard coded solutions tee Echo nothing and simple send it to multiple files using the tee command. Like this: $ echo -n | tee file1 file2 file3 file4 file5 All files in that list will be empty and created if they don't exist. Applied to your answer this would be:...
Please make a search before you ask any question many posts are already there You can try something like below, modify accordingly Input [[email protected] tmp]$ cat input.txt 1 3 2 5 3 4 4 3 5 2 6 1 7 3 8 3 9 4 10 2 11 2 12...
You have additional spaces at the declaration of IS_RUNNING. Try IS_RUNNING="$(lsof...)" ...
I think Álvaro its right about the quotes, try something like debconf-set-selections <<< "mysql-server mysql-server/root_password password $passdb" debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $passdb" ...
linux,multithreading,linux-kernel
Unlike Windows, Linux does not have an implementation of "threads" in the kernel. The kernel gives us what are sometimes called "lightweight processes", which are a generalization of the concepts of "processes" and "threads", and can be used to implement either. It may be confusing when you read kernel code...
java,linux,spring,websphere,spring-batch
You are using backslashes in the the value of fileLocation. They are valid file name characters in linux. You should change the path to /opt/temp/.
You don't need the quotes. Just use ${i}, or even $i: pomme[${i}]="" Or pomme[$i]="" ...
linux,bash,redirect,command-line,sh
Solution based on the comment from "Zaboj Campula": if /bin/grep -q "^[[:space:]]/usr/bin/enigma2_pre_start.sh$" /var/bin/enigma2.sh then echo Unpatched > /tmp/enigma.sh /bin/sed -e 's/^\t\(\/usr\/bin\/enigma2_pre_start.sh\)$/\t\. \1/g' /var/bin/enigma2.sh -i pid=`/bin/ps -o ppid= $$` && /bin/kill $pid fi ...
Just an idea, I didn't see this anywhere but: Unless you're using full paths to invoke those binaries, you could create mocks of those libraries, e.g., in your projects bin/ directory and make that directory be the first in your $PATH. export PATH="$PWD/bin:$PATH" To mock grep, for example, you could...
What you are looking for is stat or one of its variants. Specifically look at the st_mode field of struct stat. The macro you are interested in is S_ISDIR(x). Find below your modified code that demonstrates what you want: void list_file(char* directory) { DIR *d; struct dirent *dir; int dir_len...
The problem is you are using -c to cut. Don't do that. Use the -f and -d flags instead to control the delimiter and fields to output. Or use awk -F . '{print $2}' <<< "$(uname -r)". Or use IFS=. read -r _ minor _rest <<< "$(uname -r)"; echo "$minor"...
Assuming that your document is well-formed, i.e. <b> opening tags always match with a </b> closing tag, then this may be what you need: sed '[email protected]<[/]\?b>@\n&\[email protected]' path/to/input.txt | awk 'BEGIN {buf=""} /<b>/ {Y=1; buf=""} /<\/b>/ {Y=0; print buf"</b>"} Y {buf = buf$0} ' | tr -s ' ' Output: <b>data1</b>...
A workaround is to modify the sudoers file and remove the requirement of a password from your user ID for a particular script to have sudo privileges. Enter sudo visudo After this, add the details in the following manner. username ALL=(ALL) NOPASSWD: /path/to/script Another method would be to pipe the...