New answers tagged

0

You need to do one of two things: Add a "shebang" line to your script. The first line should read: #!usr/bin/env php In this case ensure that your PHP script is marked executable. Have cron call the PHP interpreter with your script as the argument. In this case, the crontab entry would be: * * * * * /usr/bin/php /path/to/script.php You need to take ...


0

The basic to execute a script with CRON is to make the file executable, talking about a php file you must give the file the path where is the interpreter command, this is called shebang (read more about in here) and must be placed at the very top of the script. So you must do the following $ chmod +x script.php $ sed -i '1 i\#!/usr/bin/php' script.php ...


0

If you want to extend python to search through additional directories, then you need to do two things: set the PYTHONPATH variable and use the -m option in Python. In ~/.zshrc (note that there is no $PATH in there): export PYTHONPATH="$HOME/python_functions/bin" And in the terminal use: python -m sleep_plotter 113testCtM113.txt which as much typing as ...


3

PATH variable defines the directories which are searched when executing commands. However when you execute python sleep_plotter.py 113testCtM113.txt, sleep_plotter.py is an argument to the python program (command). Shell uses PATH to find python, but not its arguments. You can add an executable attribute to your script: $ chmod +x ...


0

This script may help. (please remove the echo to actually mv files): #!/bin/bash shopt -s nullglob month=(Jan Feb Mar May Apr Jun Jul Aug Sep Oct Nov Dec) for y in 2016; do for m in {01..12}; do fn="$y-$m" dn="${month[10#$m-1]}_$y" [[ ! -d $dn ]] && mkdir -p "$dn" for file in ./"$fn"*.wav; do echo ...


0

### capitalization is important. Space separated. ### Null is a month 0 space filler and has to be there for ease of use later. MONTHS=(Null Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) cd /your/ftp/dir ### pretty obvious I think for file in *.wav ### we are going to loop for .wav files do ...


1

Here's what I came up with: #!/usr/bin/env python2 from deluge.log import setupLogger from deluge.ui.client import client from twisted.internet import reactor import argparse from operator import itemgetter import pprint setupLogger() def on_get_torrents_status(status): exclude_labels = args.exclude_labels.split(',') if args.exclude_labels else [] ...


0

Could you tell the error, that you get after execution, because the script is working for me. There is the same question here, answered using php and perl: Output URL of open firefox tabs in terminal Since the main part in python, here is a purely python script, to do the same thing, try it as well: #!/usr/bin/python import json f = ...


0

Quote your variables and use IFS= with read, as this: displayLine(){ printf '%s\n' "$line"; } filename="infile" while IFS= read -r line do displayLine "$line" done < "$filename"


1

On UNIX systems wildcards are handled by the shell. The escaped * in the following command is passed to cp which looks a file named /media/* and presumably that doesn't exist. cp -p -r /media/\* $pth In Windows, by contrast, the * is not handled by the command processor but by the copy command. Only root is allowed to change file ownership. Otherwise, ...


2

As for software for doing remote Windows automation tasks from the Unix/Linux side, I am aware of: Ansible - devops automation framework Rundeck - web based Java automation framework putty - pscp tools, for talking SSH on the Windows remote side cygwin - cross-compiled GNU tools framework for Windows Win32-openSSH - Microsoft´s port of OpenSSH freeSSHd - a ...


1

I'm not sure where to recommend putting the test, but the [ shell command, and the [[ bash built-in both have tests that could be used this way: for f in ... do if [[ ! -e "$f" ]] then # do work here because file $f does not exist fi done That's just an example, I'm not sure what work your loop body does, so maybe the test should go ...


0

Although there is a solution using bash arrays, there is a simpler way. The command samtools view -H sample.bam | sed -r -e '/^@RG/!d;s/\b([[:alpha:]]+):/RG\1=/g' \ -e 's/^@RG/java -jar picard.jar AddOrReplaceReadGroups I=input.bam O=output.bam /' would emit you a script that calls java -jar picard.jar for each row that matches @RG in the beginning of a ...


0

I have another perhaps simpler approach to cleaning up old print jobs. Instead of finding a way to convert the abbreviated time stamps on the print jobs, it's easier to use the find command to accomplish the task of deleting old print jobs fitting a certain criteria. For example, if you want to find print jobs older than 4 days: find /var/spool/cups -name ...


1

Put everything into a shell script and start the shell script with your shortcut.


2

With prename: Setup: $ mkdir test && cd test $ > "foo bar XXX doo par.jpg"; > "foo bar YY YY doo par.jpg" Action: $ rename -n 's/^foo bar //; s/ doo par(\.[^.]*)$/$1/' * foo bar XXX doo par.jpg renamed as XXX.jpg foo bar YY YY doo par.jpg renamed as YY YY.jpg (Remove the -n to have those moves actually performed)


1

Your best best is to set up a secure shell daemon on the system (if it's not already running) and use paswordless keypair authentication. Presuming that sshd is already in place, you can log in as tiger and run the following commands: ssh-keygen ssh-copy-id jenk@localhost After that, tiger will be able to run a command as jenk with the following syntax: ...


0

When you run that command in a pipe, it spawns a new process rather than running the command in the current shell. The new shell switches to the user jenk, but when that shell exits (since it didn't have anything else to do), your original shell which spawned that shell is still logged in as you. If you run the command in a script, it will be run in a ...


3

If the filename is in a variable, the canonical way to remove a preffix is: removepre="foo bar " filename="foo bar XXX doo par.jpg" filename="${filename#"$removepre"}" echo "$filename" The problem with the suffix you present is that there is an extension that you want to preserve, so it becomes a bit longer: removesuf=" doo par" filename="foo bar XXX doo ...


0

untested, but try #!/bin/sh nohup sxhkd </dev/null >/dev/null 2>/dev/null & nohup panel </dev/null >/dev/null 2>/dev/null & To completely disassociate them from each other


0

This doesn't work on a lot of levels. Chiefly, bash isn't really good for multi-threaded programming. But if you're going to do it this way, you have to realize two things: (1) in order for your key-read "thread" to work, it has to have exclusive access to the tty. (2) When you put a process in the background, it will naturally copy stdin from the current ...


0

The closest I could ever get with a similar issue was something like this... First create a script named inputproc: read -n1 Then create a script called mainscript: array=(W e l c o m e) buf=0 while pgrep "inputproc" > /dev/null; do echo -n ${array[buf]} ((buf++)) sleep 0.09 done #Insert any commands you want to run afterwards here... ...


0

You can put any string you like in a variable. But you can't put spaces around the equal sign in an assignment: adapter=/Volumes/My\ Passport/Documents/adapters.fa or adapter='/Volumes/My Passport/Documents/adapters.fa' After this definition, you can use "$adapter" in the shell to refer to that file. Note the double quotes — without them the shell ...


0

You can use find command to search through the root directory and see if the file with given name is present or not. This will search through all the directories and sub directories directed from the root !/bin/bash printf "\n Please enter a file name " read num3 if [ find / -type f -name $num3 2>/dev/null| wc -l -gt 0 ]; then echo "It is valid ...


2

if.. then.. fi should be fully inside for.. do.. done, you cannot cross them for k in {794..800} do if [ -f "vesta_$k.xyz" ] then mkdir "$k" mv "vesta_$k.xyz" "$k/vesta.xyz" cd "$k" || exit 3 echo '<<COMMANDS>>' cd - "$OLDPWD" fi done


1

One thing you can do is store the pid of the tomcat in a file then read that file and use the pid in kill command. To store pid of tomcat, add below line in your tomcat's catalina.sh CATALINA_PID=$CATALINA_HOME/tomcat.pid This will create a file tomcat.pid in your catalina home and store the pid of current process. Then you can just use the command ...


2

It's perfectly legal to use a variable that way; when you refer to the variable, it will resolve to that file path. This may be out of scope of your question, but the variable will only last as long as the shell it is created in, unless you add it to the environment with export or setenv, or adding it to .bashrc (or similar).


2

There are scripts for html2text, but i think what you are looking for is xpath (e.g. xmllint supports it) to get the content of some elements of your html page.


1

You just made a syntax mistake: you wrote "{$f%_1.txt}_2.txt" while the correct form is "${f%_1.txt}_2.txt" (you misplaced the $ character). :) Edit: woops, I got it wrong, because in the block "${f%_1.txt}_2.txt", f's value is still user/admin/1/2/a/preQC_1.txt so basically "${f%_1.txt}_2.txt"'s value is user/admin/1/2/a/preQC_2.txt, which is not what you ...


2

for f in ~/1/2/*/*_1.txt; do file_without_path="${f##*/}" exptool input1= "${file_without_path}" input2= "${file_without_pathf%_1.txt}_2.txt" done


0

Besides that awk(same as and another text processors) is not a right xml-parsing tool: awk ' lines{ lines=lines "\n" $0 } /<\/record/{ if(lines ~ /keyword>SEARCH</) print lines lines="" } /<record/{ lines=$0 } ' <input.txt >output.txt Same as sed sed -n ...


1

If I have understood correctly, this might be a solution in awk!: /^<record/ { x1=""; while (match($0, "record>$")==0) { x1=x1 $0"\n"; getline; } x1=x1 $0; if (x1 ~ />SEARCH</) { print x1 > "output.txt"; } } This will extract the blocks, record> to \record>, containing the key "SEARCH" ...


5

I'm going to assume that what you've posted is a sample, because it isn't valid XML. If this assumption isn't valid, my answer doesn't hold... but if that is the case, you really need to hit the person who gave you the XML with a rolled up copy of the XML spec, and demand they 'fix it'. But really - awk and regular expressions are not the right tool for the ...


1

If you want your file names in order (ie. File-1 -> File-n) in the end, you should do them sequentially. -- count=0; for i in * ; do mv $i file-${count}; ((count++)); done


1

Random might return duplicate value. How about generating numbers in sequence ? count=0 for name in *; do count=`expr $count + 1` ; echo mv $name File-$count;done


1

pre=file ; for old in * ; do new=`xxd -l 16 -ps /dev/urandom` ; while [ -f "$pre-$new" ] ; do new=`xxd -l 16 -ps /dev/urandom` ; done ; mv "$old" "$pre-$new" ; done ; xxd is a binary which usually comes with: vim-common package. xxd -l attribute refers to the random length you want. xxd -ps is to get postscript plain hexdump style names, for example: ...


4

You could maybe use shuf (from the GNU coreutils package), which generates permutations rather than individual random samples - something like for f in *; do read i; echo mv -- "$f" "file-$i"; done < <(shuf -i 1-10) or (perhaps better) shuffle the filenames - and then simply rename them sequentially i=1; shuf -z -e -- * | while IFS= read -rd '' f; ...


1

HELP 1 Due to the whitespace you need quoting: INPUT= "${file##*/}" OUTPUT= "${file%.txt}"_exd.txt It seems a bit strange, though, that there is a space between INPUT= and the file name. HELP 3 If you have a file input_1.txt then ${file%.txt}_1.txt becomes input_1_1.txt. I would match the exact file name: for file in ~/Desktop/parent\ ...


1

On your home computer, before starting the job, launch =screen=: screen Then, from work or where ever, ssh into your home machine. Once in a shell, connect to the screen instance running there: screen -raAd That's -r[eattach] -a[ll capabilities] -A[dapt the size of the screen] -d[etach screen if running elsewhere] Do whatever you want to do in that ...


4

The venerable Gnu Screen can do what you want, but it can't attach to an already running gnome-terminal. You'll need to start screen at work if you want to pick it up later at home. See Session Management specifically.


3

example.sh script to xcalc "4*9=", and view capture-result image: #!/usr/bin/env bash save="$DISPLAY" # save original X display number export DISPLAY=:44 # set random choosen display for xvfb case "$1" in # and x-programs called below start) Xvfb $DISPLAY & ;; ...


1

[ -f $num3 ] Doesn't make sense as you're applying the split+glob operator to the content of $num3. [ -f "$num3" ] Would check whether the $num3 path (absolute if it starts with a /, relative to the current working directory if not) resolves to a file that is of type regular or a symlink to a regular file. If you want to check whether $num3 relative to ...


0

If you provide the pathname to the file, your script will already work correctly. If you don't want to provide a path, you can check the presence of the file in another directory simply by providing that path in your script if [ -f "/other/dir/$num3" ] then echo "It is valid script" else echo "Invalid file name" fi


1

Try this #!/bin/bash printf "\n Please enter a file name " read num3 printf "\n Please enter the path to check " read path2check if find $path2check -name $num3 -print -quit | grep -q '^'; then echo "the file exists!" else echo "the file does not exist!" fi


4

Here is a solution built around the inotifywait utility. (You could use incron too, but you'd still need code similar to this.) Run this at boot time, for example from /etc/rc.local. #!/bin/bash # cd /path/to/samba/folder # Rename received files to this prefix and suffix prefix="some_prefix" suffix="pdf" inotifywait --event close_write --format "%f" ...


0

I think cron is a good idea! Here some input for your script: #!/bin/bash smbdir="@sambadir@" # change the @sambadir@ variable by hand smbsubdirs=(A B C D) smbprefix="@sambaprefix@" # for example for sd in ${smbsubdirs[@]}; do ssd=$smbdir/$sd && [ -d "$ssd" ] || continue for f in $(find $ssd -cnewer $ssd -type f); do if [[ "$(basename $f)" ...


0

Slight improvement on @rush's find suggestion, instead of using the -exec switch, you can avoid adding the cd command by doing something like this: find /path/to/dir/containing/subdirs -type d -execdir /path/to/your/script.sh \; This way you can avoid the for loop in your original script altogether.


2

echo /test/{1..10}/{1..15} " " | ( chars=({A..Z}); i=0; while read -d " " dir; do test -z "$dir" && break; echo mkdir -p "$dir"; echo touch "${dir}/${chars[i]}"; ((i++)); i=$((i%26)); done )


4

With zsh: dirs=(test/{1..10}/{1..15}) n=0 mkdir -p $dirs && for d ($dirs) {:>$d/$(([##36]n%26+10)); ((n++))} The trick above being to use base36 numbers where digits 10 to 35 are expressed with A.. Z. Would be a bit more legible and generalisable with: dirs=(test/{1..10}/{1..15}) n=0 l=({A..Z}) mkdir -p $dirs && for d ($dirs) : > ...



Top 50 recent answers are included