Tag Info

New answers tagged

1

This should do (note that this is untested): #!/bin/bash BASE_DIR="/var/www/testing" NEW_BASE_DIR="/var/www/testing/old" FILE_EXTENSIONS_TO_MOVE="zip" # If the new directory doesn't exist, create it if [ ! -d ${NEW_BASE_DIR} ] ; then echo "Creating ${NEW_BASE_DIR}" mkdir ${NEW_BASE_DIR} fi echo "Moving files with extension .${FILE_EXTENSION} in ...


-4

ls | grep '' As simple as that, works for me!


0

How about if you try to unzip and untar in separate steps: gunzip mediawiki-1.24.1.tar.gz This will create the file mediawiki-1.24.1.tar, and then untar with: tar xvf mediawiki-1.24.1.tar Is that better?


3

To execute a script on a server using ssh is simple, something like: cat script.sh | ssh someserver However, you probably do not want to execute the same script on every server. You will need another script to read your users.txt and from that file create script files for each line in users.txt before calling ssh with a newly created script as input. You ...


-1

Create the file /etc/motd.tail and write there everything you need. The file /etc/motd will be generated upon every system boot based on the contents of /etc/motd.tail.


-1

the find solution spawns one chown process per file, sometimes that can be a problem. This solution spawns only one perl process: find . | perl -nle "chown($(id -u user), $(id -g group), \$_) unless m/foo/"


0

Down the Network Interface Without knowing what version of Ubuntu you're running, probably the simplest thing you could do is to just bring down the network interface (assuming you've only got one): sudo ifdown eth0 Use the following to bring it back up: sudo ifup eth0


1

You could try using the following commands: (this is to disable all Internet Connections in Ubuntu) nmcli nm enable false and to enable it again: nmcli nm enable true Hope it helps! :)


0

Just get rid of the continue command, it's not needed. Leave the ;;, though -- that's how the end of a case is indicated. The purpose of continue is to skip the remainder of a loop body, and start the next iteration. It has no meaning outside a loop, so you get this error. This isn't like C/Javascript/PHP -- you don't need a special statement at the end of ...


0

If you need to supply a password and use ssl you can do something like this. #!/bin/bash -e USER=$1 MYPASSWORD=$2 IRC_SERVER=$3 IRC_PORT=$4 CHANNEL=$5 MSG=$6 ( echo NICK $USER echo USER $USER 8 * : $USER sleep 1 echo PASS $USER:$MYPASSWORD echo "JOIN $CHANNEL" echo "PRIVMSG $CHANNEL" $MSG echo QUIT ) | ncat --ssl $IRC_SERVER $IRC_PORT The script should ...


1

What you're after is findmnt. For example: $ findmnt -rn -S UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx -o TARGET /mnt/mountpoint or $ findmnt -rn -S PARTUUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx -o TARGET /mnt/mountpoint If nothing is mounted matching that UUID, nothing is output and the return code is 1 (failure), otherwise, the mountpoint is output ...


4

if fgrep -q 'reset adapter' /var/log/messages.log; then mail -s 'Flapping ethernet' alerts@OurAlertBoard.com fi Note the added ; before then Also, you need to keep grep quiet and only return an error code. This is done with -q On most systems, the log files is named /var/log/messages. Check if messages.log is correct on your system.


0

According to the man page for Signal (man 7 signal) a SIGBUS means Bus error (bad memory access). Since the problem is random or not easily reproduced 100% of the time, this means either; The Cron job is calling a program or script that is randomly failing A memory problem exists and should be checked for If it is the former (#1), then check the program ...


0

It depends a bit on how you configure Apache to format your access_log. If you're using the common "CLF" logformat: LogFormat "%h %l %u %t \"%r\" %>s %b" common CustomLog logs/access_log common Then the 7th field contains the request URL. A quick bit of awk which is always present and fairly efficient at parsing text. (Linux almost always has the ...


0

Answering my own question here. It was difficult to follow the flow of control in the scripts above, I think I'm settling on something like this: #!/bin/bash # Generate the foo report # source the shared code/vars if we're running locally [[ -f shared.sh ]] && source shared.sh if [[ "$report_host" != "$(hostname)" ]]; then # ssh-agent will ...


2

To fit with modern sysadmin best practices it would be good to add your configs as individual files in /etc/smb/smb.d and then reference them with an include. Sadly samba does not support wildcard includes so you have to do add something like: include = /etc/smb/includes.conf in your smb.conf and then generate the includes.conf with something like: ls ...


0

cat filea <(echo) fileb > filec


1

Unless I misunderstand, how about you append cat filea >> fileb You can do a sort afterwards, if that's what you're after.


1

Use exit followed by the value you want. Zero is considered success, non-zero failure. This is typically used within a script, and terminates the (sub)shell it is exited from. If you want to capture the status of a command, assign $? to a variable. This allows you to save the value after displaying it.


0

Enable logging for the job-execution subsystems. More specifically, cron and at will log to syslog by default, so you simply need to ensure the logged events are persisted. You might want to add the following to your /etc/syslog.conf ## Log cron and at to /var/adm/scheduled.log cron.* /var/adm/scheduled.log After adding that, reboot the syslog daemon, to ...


0

You could check the parent process name by using the ${PPID} environment variable and looking for that in ps.


5

Don't reinvent the wheel :) The Monit utility is purpose-built to handle this sort of situation. It's well-documented and has plenty of examples here on ServerFault. check system kale.GreenLeaf.com if loadavg (5min) > 16 for 15 cycles then alert if memory usage > 92% then alert if swap usage > 10% then alert or for a process: ...


2

What exactly are you trying to accomplish? You're probably trying to do it WRONG. [ $(free | perl -nE 'if (/Mem/) { (undef,$total,$used) = split; say int(100*$used/$total) }') -gt 80 ] && echo foo But note that whatever you are trying to accomplish with that is almost certainly useless (and probably even harmful). There is no such thing as ...


4

How about: [ $(free -m| grep Mem | awk '{ print int($3/$2*100) }') -gt "80" ] && echo "greater " || echo "lesser" And for the process consumption, here is a possible part of a solution: for p in $(pgrep bash); do total=$(($total + $(awk '/VmSize/ { print $2 }' /proc/$p/status))); done ; echo "Total memory usage: $total kb" ; unset total ...


-1

Ctrl + C helps only if network is slow or not reachable. But sometimes the problem is if it freezes for longer than you expect or never comes back, even after Ctrl + C or Ctrl + Z or any combination, where you end up just closing the terminal. Then please check your PATH variable, if it is not set for any path mounted on network, you are not able to reach ...


1

You can also use cut like this : for file in /a/dir/*/dir/* ; do echo \`echo $file | cut -d"." -f 1` >> textfile; done It will only work if you don't have any file or directories with a "." in the name


0

I think it may be that the file doesn't have permissions to run without bash (should be able to rectify by running "chmod +x" and your second command shouldn't include the "-c" switch to bash and the filename also doesn't need to be quoted.


1

Using date and expr can get you there i.e. X=$(expr \`date +%H\` \\* 3600 + \`date +%M\` \\* 60 + \`date +%S\`) echo $X Just expand on it to do whatever you want I realise this does not give milliseconds since epoch, but it might still be useful as an answer for some of the cases, it all depends on what you need it for really, multiply by 1000 if you ...



Top 50 recent answers are included