Tag Info

New answers tagged

1

Edit this file as root: /etc/pam.d/su Search and uncomment this line in the file removing #: # session required pam_limits.so Reboot and test.


0

Why don't just do python /home/user/breve_2.7.2/demos/Getting-Started/RandomWalker_version.py in the last line. That should solve it (when the shebang is correct).


0

Since you have multiple python versions installed and you want to determine which python is to be used as default, you should use update-alternatives command which maintains symbolic links determining default commands. First of all run this: update-alternatives --list python If the result is: update-alternatives: error: no alternatives for python Then ...


1

I tested but realized I would need to track down all the possible sources of color like commands, the command prompt itself, etc. This is a sed filter from commandlinefu.com that works great if you pipe anything through it. Of course you can save the output once piped like this: cat test.txt | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" > ...


5

As I mentioned in my comment there are some vital pieces missing here and these commands together don't quite make sense, but I will go over them. if [ ! -w "." ]: . represents the current directory. -w tests if it is writeable. ! negates the test (so the statement returns true if the directory is not writeable vs the other way around). ps -d | grep ...


0

If you are trying to output both STDERR and STDOUT of every command run to a file, you can use >> $logfile &> Example: #!/bin/bash <command> <arguments> >> $LOGFILE &> <command> <arguments> >> $LOGFILE &> In this example, a logfile will be created with the value you set the LOGFILE variable ...


1

Here are your errors (source): SC2002 Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead. SC2006 Use $(..) instead of legacy ... SC2046 Quote this to prevent word splitting. SC2086 Double quote to prevent globbing and word splitting SC2126 Consider using grep -c instead of grep|wc. 1 #!/bin/bash 2 #Script to create unique and ...


0

I solved with Guacamole (http://guac-dev.org). With a php script it could be dangerous and with teamviewer it freezes because every time I have to stop the demon with "teamviewer --daemon stop" from a remote terminal (very complicated if you connect from a mobile).


0

Try using operators, #!/bin/bash if [ "$1" -lt 70 ] && [ "$1" -gt 33 ]; then echo "OK" else echo "Nope" fi In this case we used, -lt (Less Then) and -gt (Greater Then). Check the link for more and others. The && you read as AND, so both conditions need to be satisfied, else the statement fails and it moves on to else. OR is ...


-1

Some thoughts: myscript alias1 "$HOME/dir/ascript" will evaluate in test part to [ -f '/home/me/dir/ascript' ] which may be true or false. myscript alias2 '$HOME/dir/anotherscript' will evaluate in test part to [ -f '$HOME/dir/ascript' ] which is always false (unless you have a dir named $HOME in local dir). and myscript alias3 ...


-1

Here you're a corrected and improved script: #!/bin/bash ################################################### ## Script to create permanent and unique aliases ## ################################################### [ -f "$HOME/.bash_aliases" ] || touch "$HOME/.bash_aliases" # If .bash_aliases does not exists, then create it. if [ $# -ge ...


-2

Here is a corrected version. #!/bin/bash # Script to create permanent and unique aliases _add_alias() { echo "alias $1='$2'" | sudo tee --append "$HOME/.bash_aliases" > /dev/null echo "Alias created" } if [ "$#" -ne 2 ] then echo "Usage: $0 <alias_name> <command>" elif [ $(echo "$2" | awk -F' ' '{system("type " ...


6

Use the following grep expression: grep -vFf file_B file_A Here is a test: $ cat file_A bird, snake dog, cat rabbit,fox eagle,dove $ cat file_B dog dove $ grep -vFf file_B file_A bird, snake rabbit,fox -f will read the patterns from a file (one per line), file_B in this case -F will consider the patterns read from file_B as fixed string, ...


1

There are configuration management and automation programs that can do exactly what you need. Rather than going through all the computers and manually do the same work over and over again, you should seriously use any of the automation/orchestration tools. Using these tools you can just create a file containg the steps and then run the file on your ...


1

I think you are right, adding a soft link to /usr/local/bin would be much better and doing a real .deb package for your scripts


1

Use this: ping -c 4 google.com | awk -F "[=]|[ ]" '/bytes from/{print NR "\t" $11/1000 }' > out.txt -c 4 (eg. 4) Limit the number of requests, so that "awk" can write to a file. $11/1000 Conversion of milliseconds to seconds


3

Improved and commented code: #!/bin/bash num=${1:-undefined} # If $1 (the first argument passed to the script) is set, then num=$1, else num=undefined. cmd=$(which {banner,echo} | head -1 | xargs basename) # If banner is installed, then cmd=baner, else cmd=echo. until [[ "$num" =~ ^[0-9]+$ ]]; do # ...


3

The NUM=${1:-0} line means that the variable NUM is set to $1 if a parameter is passed to the script, and to 0 if no parameter is passed at all. That explains why you have no output at all; the threshold is always set to 0 if the script is executed without passing a parameter to it, e.g.: bash <script_name> *<script_name> = name of your bash ...


2

#!/bin/bash printf "Type an integer number: " && read NUM if [ $NUM -gt 0 ] then while [ $NUM -ge 0 ] do if [ -f /usr/bin/banner ] then /usr/bin/banner "$NUM" else echo $NUM fi NUM=$(($NUM-1)) sleep 2 done fi output: :~$ ./countdown.sh Type an integer number: 10 10 9 8 7 6 5 4 ...


0

Start the script with a parameter and it works: ./countdown 20 And use this: while [ $NUM -ge 0 ] #!/bin/bash #countdown #counts down to 0 from whatever number you give it #displaying a number each second NUM=${1:-0} if [ $NUM -gt 0 ] then while [ $NUM -ge 0 ] do if [ -f /usr/bin/banner ] then /usr/bin/banner $NUM else ...


0

Another suggestion is to create executable bash script. Lets call it onboot.sh and save it in your home directory ~/onboot.sh #!/bin/bash sleep 20 echo 'cpu limit bomi player at 40%' cpulimit -v -e bomi -l 40 then make it executable by running this command chmod +x ~/onboot.sh then add this line to your ~/.bashrc ~/onboot.sh & Every ...


1

To have it add ppa.launchpad.net lines as ppa:$USER/$PPA. Add other repositories with their full line from *.list files. No dupe lines. #!/bin/bash # My ~/bin/mk_repositories_restore_script mkdir -p ~/bin x=~/bin/restore_repositories echo \#\!/bin/bash > $x chmod u+x $x ( for APT in $( find /etc/apt/ -name \*.list ) do sed -n -e '/^deb /{ ...


0

Here's a generalized update to @geirha's answer. ############ wrapper over apt-get to download files (retries if download fails) and then perform action. ############ usage example: aptgethelper install "nethogs rar -y -qq --force-yes" function aptgethelper(){ local __cmd=$1 local __args=$2 local retry=10 count=0 set +x # retry at most $retry times, ...


1

What you're doing here is kind of peculiar. The resulting names would be: 5 (was: 1) 6 (was: 3) The first operation (mv 1 4) would have removed the original "4" directory and replaced it with one. There's a couple of ways to work around this, and two that I can think of off the top of my head would be: Renaming all the directories to something with a ...


0

Every script placed in folder /etc/cron.hourly would run on hourly basis. However your files needs to be: executable, match the Debian cron script namespace (^[a-zA-Z0-9_-]+$). So for example if you've script with extension, it won't work. To print the names of the scripts which would be run, try: sudo run-parts --report --test /etc/cron.hourly


0

If mlog.log is space separated: cat mlog.log |perl -a -ne 'chomp($F[0]=`date -d \@$F[0] +%FT%T`); print join(" ",@F)."\n"' If mlog.log is tab separated: cat mlog.log |perl -a -F"\t" -ne 'chomp($F[0]=`date -d \@$F[0] +%FT%T`); print join("\t",@F)."\n"'


0

You could maybe try enter this paragraph to it: noadm="false" noadm=(v) and to the mysql -v and it might work fine this way.


3

If you're looking for a system command that always returns a non-zero exit code, then /bin/false seems like it should work for you. From man false: NAME false - do nothing, unsuccessfully SYNOPSIS false [ignored command line arguments] false OPTION DESCRIPTION Exit with a status code indicating failure.


2

You can create a new return code with the command bash -c "exit RETURNCODE", replacing "RETURNCODE" with any number. Note that it will be trimmed to an 8bit unsigned integer (0...255) by (RETURNCODE mod 256) You can check the return code of the last shell command inside the terminal(!) with executing echo $?. The "$?" variable contains the most recent ...


0

After some more testing, I found that my problem was not on the "Linux" side. Python has a module shlex; which should be used to "split" command strings. When I changed my subprocess call to use the output of shlex.split() invoking "bash exit 1" gives me what I need.


-1

You could also enter this in the terminal: crontab -e and then type this in: @reboot /path/to/script and in the script type in at the beginning this: sleep 20 and it might work fine this way.


0

The <!DOCTYPE html> line is a DOCTYPE declaration for HTML documents, so it looks like you are fetching a web page instead of the script. Either open the script link in your browser and copy-paste the script source manually into a text file and save it as "10_1_1.sh" in your terminal's working directory, or try to use curl in place of wget (in either ...


5

A simple way of doing that is to add those lines to rc.local in your system. For that you need root or sudo rights. You can edit the file with your favourite text editor, eg vim: vim /etc/rc.local (sleep 20 echo 'cpu limit bomi player at 40%' cpulimit -v -e bomi -l 40) & The first line tells the the computer to wait 20 seconds, the other 2 lines are ...


0

The timeout command does exactly what you seem to want. See man timeout: NAME timeout - run a command with a time limit SYNOPSIS timeout [OPTION] DURATION COMMAND [ARG]... timeout [OPTION] DESCRIPTION Start COMMAND, and kill it if still running after DURATION.


2

echo firstOutput read -s command0 & sleep 8 command1a & command1b & command1c & sleep 5 echo secondOutput command2


2

You could do something like sensors -A | grep -oP '^Core.+? \+\K\d+' | awk '{k+=$1}END{print k/NR}' The grep will print only the relevant numbers (the spaces ensure that only the actual temperature is printed, not the critical or anything else) and the awk does the calculation. NR is the number of lines so that will work if the number of cores changes.


7

Using the "raw output" mode of sensors for easier scripting: -u Raw output. This mode is suitable for debugging and for post- processing of the output by scripts. It is also useful when writing a configuration file because it shows the raw input names which must be referenced in the configuration file. For example: $ ...


1

You can get the number of processors using grep -c ^processor /proc/cpuinfo


2

Joining commands with && means that the command on the right will only run if the one on the left was successful. This means that your crontab will fail the first time it is run since there is no zip file in /var/www/html/ so the rm /var/www/html/my-zip-file*.zip fails and the mv will not be executed. So, you can either create a file of the right ...


0

This illustrates why you should NEVER rely on parsing the output of the ls command to iterate over directory contents - use a simple find command: find . -maxdepth 1 -type d --regex './[0-9]+$' -exec cp $1 {} \;


0

Without a command, SSH runs a login shell. For bash, that involves sourcing .profile (which, on Ubuntu, sources .bashrc) (and /etc/profile, which sources /etc/bash.bashrc). There are other files which could be sourced instead, such as .bash_profile, but a default Ubuntu setup has only .profile. $ grep bashrc /etc/profile .profile /etc/profile: # The file ...


1

This page has more than you probably want to know about it, but it's a great concise resource: http://mywiki.wooledge.org/DotFiles Basically, when you ssh to a computer, you are not running a 'login' shell, so different files are sourced. In short, if your default shell is /bin/bash (default on Ubuntu), you will be sourcing a ~/.bashrc in your home ...


1

My solution would be to use find: find /home/WORKDIR/ -name "input*.o" -exec gd2p.pl -i {} \; That gives you (virtually) unlimited depth in sub-folder structure.


0

You can try this code. for file in */*; do # Loop trough any file in any folder if [ -f "$file" ]; then # If the current element is a file gd2p.pl -i "$file" # Run the program fi # End if done # End loop


0

On Ubuntu 12.04: Open Nautilus . Hit Alt. Type preferences. Hit Enter. Choose Behavior tab. Under Executable Text Files choose Ask each time. You also need to mark your files as executables. To do that right click the .sh file, choose Properties, and under the Permissions tab check Allow executing file as a program.


0

here is lsusb -v (as requested by CL) Bus 003 Device 003: ID 200c:100a Reloop Couldn't open device, some information will be missing Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 2.00 bDeviceClass 255 Vendor Specific Class bDeviceSubClass 255 Vendor Specific Subclass bDeviceProtocol ...


0

I added the following to /etc/lightdm/lightdm.conf on Ubuntu Precise: [SeatDefaults] session-cleanup-script=/usr/local/bin/script-to-run Works nicely every time. Source: http://ubuntuforums.org/showthread.php?t=1969822&p=11892228#post11892228


1

If you keep your local ip executable called ip, and not something longer, you can avoid this particular problem. If you rename it to some other one or two character long name, that will also work fine--the problem only happens if its name is three or more characters in length. This may seem strange... so read on for details... When I run a copy of /bin/ip ...


16

Rewriting the loop this way reveals what is happening: echo '1 2 3 4 5 6' | while read a b c do echo '(iteration beginning)' a="$a" b="$b" c="$c" '(iteration ending)' done This gives, as its output: (iteration beginning) a=1 b=2 c=3 4 5 6 (iteration ending) Notice first that only a single echo command is run. If it were run more than once, you ...


21

read reads a whole line from standard input, splits the line into fields and assigns this fields to the given variables. If there are more pieces than variables, the remaining pieces are assigned to the last variable. In your case $a is assigned 1, $b is assigned 2 and $c the remaining 3 4 5 6.



Top 50 recent answers are included