Search This Blog

Showing posts with label Scripting. Show all posts
Showing posts with label Scripting. Show all posts

Tuesday, May 24, 2016

Linux: copy multiple files without asking overwrite confirmation

Linux: copy multiple files without asking overwrite confirmation

To always overwrite without prompt use a backslash:
$ \cp *.jpg ../

Linux: how to rename multiple files at once

Linux: how to rename multiple files at once

Very easy:

rename from to files...
rename JPG jpg *.JPG

Wednesday, October 9, 2013

Simple access SVN Subversion repository behind proxy

Uncommenting and set the following lines: 

[global]
http-proxy-host=my.proxy
http-proxy-port=80
http-proxy-username=[username]
http-proxy-password=[password]

in file
~/.subversion/servers

Wednesday, October 2, 2013

Simple essential TAR usage

create archive:
tar -cvf test.tar /home/test/
extract archive:
tar -xvf test.tar
list archive content:
tar -tvf test.tar

Thursday, August 29, 2013

QNAP: Automatically run a script at startup

Running Your Own Application at Startup
QPKG-based method (new)
This method consists of declaring a dummy QPKG which launches your script at startup.

Log into your QNAP device using SSH or Telnet, for instance by using Putty

Edit QPKG config file:
# vi /etc/config/qpkg.conf

Declare a new dummy package by adding something like that in this file:

[autorun]
Name = autorun
Version = 0.1
Author = neomilium
Date = 2013-05-06
Shell = /share/MD0_DATA/.qpkg/autorun/autorun.sh
Install_Path = /share/MD0_DATA/.qpkg/autorun
Enable = TRUE

As you can see, Shell is the interesting variable: at boot-time, QNAP OS will launch each QPKG's Shell variable content.

Note: if your NAS doesn't have /share/MD0_DATA (i.e. is a one-drive NAS), put the right directory into the Shell and Install_Path variables and adapt the following commands to your needs.

Create the dummy package directory:
# mkdir /share/MD0_DATA/.qpkg/autorun

Create the autorun script with the contents of your choice:
# vi /share/MD0_DATA/.qpkg/autorun/autorun.sh
Note: don't forget "#!/bin/sh" at the beginning of script.

Set the execute bit:
# chmod +x /share/MD0_DATA/.qpkg/autorun/autorun.sh
Reboot and enjoy!

from

Wednesday, August 21, 2013

Check blackout length (for BeagleBone Black)

timer.sh:
root@beaglebone:~/Desktop# cat timer.sh

#!/bin/bash

KEEPALIVE=/home/root/Desktop/log.txt
#TARGET=/home/root/Desktop/log_$(date -r $SOURCE +"%Y-%m-%d_%H-%M-%S").txt
TARGET=/home/root/Desktop/log_$(date -d "today" +"%Y-%m-%d_%H-%M-%S").txt
BOOT=/home/root/Desktop/boot.txt


# se esiste bootfile salva log.txt con ora corrente
if [ -e $BOOT ]
then
echo "$BOOT exist"
mv $KEEPALIVE $TARGET
rm $BOOT
fi

echo $(date -d "today" +"%Y-%m-%d %H:%M:%S") > $KEEPALIVE

timerboot.sh:
root@beaglebone:~/Desktop# cat timerboot.sh

#!/bin/bash

TARGET=/home/root/Desktop/boot.txt

echo "boot" > $TARGET

crontab:
root@beaglebone:~/Desktop# crontab -l

30 * * * *    /usr/bin/ntpdate-sync silent
*/5 * * * * /home/root/Desktop/timer.sh
@reboot /home/root/Desktop/timerboot.sh

Linux scripting to save blackouts hours

In my house sometimes I got a blackout, don't know why yet, but it happens.
Now, I want to know for how long blackout lasted.
I made up some simple bash scripting for this; possible next actions, link this info to a nagios or ninjablock application to receive notifications:

timer.sh:
root@beaglebone:~/Desktop# cat timer.sh

#!/bin/bash
TARGET=/home/root/Desktop/log.txt
echo $(date -d "today" +"%Y-%m-%d %H:%M:%S") > $TARGET

timerdown.sh: 
root@beaglebone:~/Desktop# cat timerdown.sh

#!/bin/bash
SOURCE=/home/root/Desktop/log.txt
TARGET=/home/root/Desktop/log_$(date -r $SOURCE +"%Y-%m-%d_%H-%M-%S").txt
touch $TARGET
mv $SOURCE $TARGET

crontab:
root@beaglebone:~/Desktop# crontab -l

30 * * * * /usr/bin/ntpdate-sync silent
*/5 * * * * /home/root/Desktop/timer.sh
@reboot /home/root/Desktop/timerdown.sh