Hot answers tagged

35

The documentation for the sleep command from coreutils says: Historical implementations of sleep have required that number be an integer, and only accepted a single argument without a suffix. However, GNU sleep accepts arbitrary floating point numbers. See Floating point. Hence you can use sleep 0.1, sleep 1.0e-1 and similar arguments.


28

Bash has a "loadable" sleep which supports fractional seconds: $ cd bash-3.2.48/examples/loadables $ make sleep && mv sleep sleep.so $ enable -f sleep.so sleep Then: $ which sleep /usr/bin/sleep $ builtin sleep sleep: usage: sleep seconds[.fraction] $ time (for f in `seq 1 10`; do sleep 0.1; done) real 0m1.000s user 0m0.004s sys ...


22

You do this by creating a subroutine you want to call when SIGINT is received, and you need to run trap 'subroutinename' INT. Example: #!/bin/bash int_handler() { echo "Interrupted." # Kill the parent process of the script. kill $PPID exit 1 } trap 'int_handler' INT while true; do sleep 1 echo "I'm still alive!" done # We never ...


18

Cheap n' dirty way: Loop stat -c %Y file and take action when the modification time changes. Probably better: Use the inotify cron service to watch for file modification events and run your action: /path/to/your/file IN_MODIFY /path/to/your/script $#


16

Edit: I ran this with your source file in my environment and have the following results: [root@xt ~]# time tiff2ps test.tif > test.ps real 0m0.795s user 0m0.659s sys 0m0.135s [root@xt ~]# time ps2pdf13 -sPAPERSIZE=a4 test.ps > test.pdf real 0m0.592s user 0m0.513s sys 0m0.075s [root@xt ~]# time tiff2ps test.tif | ps2pdf13 ...


14

Both for MySQL and PostgreSQL you can specify your user and password in local config file. .my.cnf for MySQL and .pgpass for PostgreSQL. These files should be in your home directory (i.e. ~/.my.cnf). .my.cnf: [mysql] user=user password=password .pgpass: host:port:database:user:password You can have a wildcard entry here, substituting any field for ...


13

Sleep accepts decimal numbers so you can break it down this like: 1/2 of a second sleep 0.5 1/100 of a second sleep 0.01 So for a millisecond you would want sleep 0.001


13

I think you are almost there. put a / at the end of your directory spec jsmith ALL=(ALL) NOPASSWD: /usr/local/tomcat7/bin/ From the sudoers man page A directory is a fully qualified path name ending in a '/'. When you specify a directory in a Cmnd_List, the user will be able to run any file within that directory (but not in any subdirectories ...


13

command1 & command2 Will execute command1, send the process to the background, and immediately begin executing command2, even if command1 has not completed. command1 ; command2 Will execute command1 and then execute command2 once command1 finishes, regardless of whether command1 exited successfully. command1 && command2 will only execute ...


12

Well the ";" makes the shell wait for the command to finish and then continues with the next command. The "&" will send any process directly into the background and continues with the next command - no matter if the first command finished or is still running. So "&;" will not work like you expect. But actually I'm unsure what you expect. Try ...


12

On a default UNIX-like system, cron has a minimal environment defined. Usually HOME, SHELL, LOGNAME are defined and PATH is set to /bin. You have two solutions: enter the full path of your script. ie: /home/me/bin/ec2-automate-backup.sh alter the PATH environment variable. If you want to receive email from the cron daemon define the MAILTO variable. ...


11

If the teamcity start script is a LSB-compliant init script (that is, if it provides start, stop and other arguments), you can just copy the script to /etc/init.d folder and run (as root): # chkconfig --add <script_name> # chkconfig <script_name> on A symbolic link for the file should be OK too. So try (as root): # ln -s ...


10

if [ $(mysql -N -s -u root -p -e \ "select count(*) from information_schema.tables where \ table_schema='db_name' and table_name='table_name';") -eq 1 ]; then do something else echo "table <table_name> does not exist" exit 1 fi -N to skip column names -s for nontabular output


10

Your condition isn't actually calling check_space, you need something like: if [ `check_space` -gt "85" ]; then


9

Most interpreters have a parameter to specify some code to execute. You can use this to invoke a specific interpreter and provide the code. For example: bash -c 'function run_free() { free -m; }; run_free' (Note that you need some semicolons in there since you don't have newlines.) perl uses -e, and python uses -c.


9

Instead of using the psql \password command, which expects an interactive terminal, you can use: ALTER USER postgres WITH PASSWORD 'newpassword'; Say, via a psql -c command: sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD 'newpassword';"


9

The $? is evaluated before the command is sent to the remote machine. Effectively, you are sending the command echo 0. Try ssh server ' <some command >; echo $? ' As Michael Hampton points out, single quotes prevent evaluating variables etc. before sending them to the remote command, while double quotes allow that.


9

Yes, you can mount a windows share into the linux filesystem using mount.cifs e.g. mkdir /mnt/windowsfs mount -t cifs //server/share -o username=user,password=P4ssw0rd /mnt/windowsfs Once you've done that you can (with suitable permissions) access and manipulate the files in /mnt/windowsfs.


9

You disable it by adding the following line in your script: set -o noglob As an example, echo * your files and folders are shown here.. set -o noglob echo * *


8

You can put it into "": $ ls file1 file2 file3 file4 file5 file6 file7 file8 file9 $ Q='select * from table;' $ echo $Q select file1 file2 file3 file4 file5 file6 file7 file8 file9 from table; $ echo "$Q" select * from table;


8

Instead of constantly pulling a directory this way, maybe try to use the inotify subsystem, which is designed for this purpose. For user space tools, have a look at the inotify-tools.


8

Look at the autodie core module. This replaces calls like open and fork with functions that die on failure. To get it to work with system, you need to import :all or :system, since the default does not do so. use strict; #always! use warnings; #always! use autodie qw(:system); system('/bin/false'); #This will die print "This will never be printed\n"; ...


7

Try sed "6s/old/new/g" file.txt


7

Use a heredoc. cat > /etc/apache2/sites-available/"$1" << EOF <VirtualHost> ServerAdmin support@$1 ... EOF


7

Try adding -t -t to your SSH connection options. This will; force a pseudo-terminal to be allocated. Multiple -t options force tty allocation, even if ssh has no local tty.


7

Alright, I should have done this to start with: FTPHOST="domain.com" FTPUSER="xxxxxx" FTPPASS="xxxxxxxxx" MEDIAFILE=/path/to/something.enc if [ -r $MEDIAFILE ] # File seems to exist and is readable then ftp -n $FTPHOST <<END_SCRIPT quote USER $FTPUSER quote PASS $FTPPASS cd backups bin put $MEDIAFILE something.enc quit END_SCRIPT fi I added the ...


7

On the CentOS box I have to hand dig +short www.google.com 74.125.132.147 74.125.132.99 74.125.132.103 74.125.132.104 74.125.132.105 74.125.132.106 If you only want one address then dig +short www.google.com | head -1 or dig +short www.google.com | tail -1


7

Use the modulo operator (bash specific syntax): if [ $(($counter % 600)) -eq 0 ] ; then echo " still in process wait another 10 min .." fi Or more portable: if [ `expr $counter % 600` -eq 0 ] ; then echo " still in process wait another 10 min .." fi


7

Use the find command with the -user option. Something like: find / -user john will eventually turn up all files owned by user "john". If you want to change their ownership (I would run the find without execution to make sure you have the list you want), then something like: find / -user john -exec chown harry {} \; will do it.


7

Try adding this to your httpd.conf; RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} From here - >http://www.sslshopper.com/apache-redirect-http-to-https.html This uses mod_rewrite so make sure you have that installed beforehand. The recommended method is as you state to set this in the VHOST file for each ...



Only top voted, non community-wiki answers of a minimum length are eligible