sed -i 's/\r$//' filename.sh
Архив рубрики: linux
ubuntu run
#!/bin/bash . /usr/local/rvm/scripts/rvm service mongodb start service redis-server start service ssh start service mysql start cd /mnt/c/sites/project (bash faye_project.sh &) exec /bin/bash
Autorun many things
- Use chkconfig — about, link
- DaemonController library. It will enable you to auto-start services with your Rails app, starting them if they aren’t already started.
- Create an initializer containing (about):
Thread.new do
system("rackup faye.ru -s thin -E production")
end
-
On Ubuntu, you should use the operating systems’s init system — Upstart.
user@host:~$ cat /etc/init/faye.conf description "Faye Upstart script" start on startup stop on shutdown respawn script env RAILS_ENV=production exec sudo -u deployuser -i /home/deployuser/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/bin/rackup /var/www/booko.com.au/booko/faye.ru -s thin -E production end script
I’m not happy with the method of calling Ruby since it will change. But the advantages are that it will start when the system starts and it will respawn if it dies or you KILL it.
Let Upstart take care of demonising a process and making sure it keeps running
-
Shell script in config/thin_example.sh
#!/bin/sh set -e # Feel free to change any of the following variables for your app: TIMEOUT=${TIMEOUT-60} APP_ROOT=/home/deployer/apps/example/current PID=$APP_ROOT/tmp/pids/thin.pid CMD="cd $APP_ROOT; bundle exec rackup -D -P $PID $APP_ROOT/config/faye.ru -s thin -E production" AS_USER=deployer set -u startme(){ run "$CMD"} stopme(){ run "pkill -f $PID"} run (){if["$(id -un)"="$AS_USER"];then eval $1 else su -c "$1"- $AS_USER fi }case"$1"in start) startme ;; stop) stopme ;; restart) stopme; startme ;;*) echo "usage: $0 start|stop|restart">&2 exit 1;; esac
Loosely modified from the unicorn scripts that Ryan Bates used in his VPS deployment railscast (pro only).
Make it executable
chmod +x config/thin_example.sh
You’ll need to symlink it to init.d (after chmod +x ‘ing to make it executable)
sudo ln -nfs /home/deployer/apps/example/current/config/thin_example.sh /etc/init.d/thin_example
Then if you want it to startup with the server
sudo update-rc.d thin_example defaults
Otherwise you should just be able to
/etc/init.d/thin_example [start|stop|restart]
. An important point to note is that I’m telling rackup to start in daemon mode (-D) and explicitly setting the PID so I can kill it late
Перенаправить почту root’а на email
Проблема такая: все уведомления от сервисов падают в локальный ящик рута: /var/spool/mail/root, а требуется, чтобы они уходили на внешний почтовый ящик. Для этого открываем файл: /etc/aliases, ищем внизу строку «#root: marc» и заменяем её на: «root:nrg@domain.ru». После изменений необходимо запустить программу newaliases, чтобы перестроить таблицу алиясов сендмыла. Теперь для очистки мусора из системы можно очистить файл /var/spool/mail/root.

ftp centos
В качестве FTP сервера будем использовать VSFTPD
Справка
vsftpd (англ. Very Secure FTP Daemon) — FTP-сервер с поддержкой IPv6 и SSL.
Является FTP-сервером по умолчанию многих операционных систем, и обслуживает официальные репозитории ftp.debian.org, ftp.redhat.com,[1]ftp.openbsd.org, ftp.freebsd.org. А так же используется на официальном FTP ядра Linux[1] [2]
http://ru.wikipedia.org/wiki/Vsftpd
Приступаем к установке
yum install vsftpd
По окончании установки отредактируем конфиг нашего будущего FTP сервера
mcedit /etc/vsftpd/vsftpd.conf
Конфиг файла довольно легко читаем. Большинство параметров так и оставляем без изменений. Ниже я укажу лишь то, что нам нужно отредактировать или добавить.
anonymous_enable=NO
Запрещаем анонимным пользователям использовать наш сервер.
chroot_local_user=YES
Добавляем эту запись в конфиг, что бы запереть пользователя в своей домашней директории
На этом, все операции с конфигом закончены. Запускаем наш сервис
service vsftpd start
Добавляем его в «автозагрузку»
chkconfig vsftpd on
Теперь, нам необходимо добавить пользователя который, собственно и будет использоваться для подключения к FTP.
useradd FTPuser
(где FTPuser - ваш пользователь для FTP)
Задаем пароль для этого пользователя
passwd FTPuser
И напоследок, немного «поколдуем» над правами этого пользователя. Ведь нам совсем не нужно, что бы этот юзер входил на сервер по SSH. Поэтому внесем изменения в файл /etc/passwd
mcedit /etc/passwd
Находим в этом файле следующую запись
FTPuser:x:501:501::/home/FTPuser:/bin/bash
И заменяем /bin/bash на
/sbin/nologin
Здесь же мы можем поменять домашний каталог этого пользователя (/home/FTPuser) на любой другой (например /VAR/FTP)
В итоге получаем следующий файл
FTPuser:x:501:501::/home/FTPuser:/sbin/nologin
Main commands and configs
Commands:
service redis-server start service mongodb start service ssh --full-restart source /usr/local/rvm/scripts/rvm
Packages:
- AngularJS
- BracketHighlighter
- LESS
- Package Control
- SFTP
- ColorPicker
Config:
{ "bold_folder_labels": true, "caret_style": "phase", "color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme", "enable_tab_scrolling": false, "fade_fold_buttons": false, "fallback_encoding": "Cyrillic (Windows 1251)", "font_size": 13, "highlight_line": true, "highlight_modified_tabs": true, "ignored_packages": [ "RubyTest", "SublimeREPL", "Vintage" ], "line_padding_bottom": 1, "line_padding_top": 1, "show_encoding": true, "tab_size": 2, "translate_tabs_to_spaces": true, "update_check": false, "word_wrap": true }
XnView on Ubuntu
sudo apt-get update sudo apt-get install gdebi sudo apt-get install gstreamer-tools sudo apt-get install ubuntu-restricted-extras sudo apt-get install libgstreamer-plugins-base0.10-0
After install XnView for Linux with package.
plink proxy
plink -ssh адрес_SSH_сервера -C -N -l логин -pw пароль -D 127.0.0.1:8081
After for:
Browsers: в графу «Узел SOCKS» укажите адрес 127.0.0.1, порт 8081, поставьте галочку «SOCKS5»
Programs: FreeCap
kill process by name
ps aux | grep 'rails'| grep -v 'grep'| awk '{ print $2 }'| xargs kill -9
find files between two dates
It’s two steps but I like to do it this way:
First create a file with a particular date/time. In this case, the file is 2008-10-01 at midnight
touch -t 0810010000/tmp/t
Now we can find all files that are newer or older than the above file (going by file modified date. You can also use -anewer for accessed and -cnewer file status changed).
find /-newer /tmp/t
find /-not -newer /tmp/t
You could also look at files between certain dates by creating two files with touch
touch -t 0810010000/tmp/t1
touch -t 0810011000/tmp/t2
This will find files between the two dates & times
find /-newer /tmp/t1 -and -not -newer /tmp/t2
Other Example
The syntax is as follows:
ls -l | grep 'yyyy-mm-dd' ls -l | grep --color=auto '2006-01-05' |
Where,
- 2006 – Year
- 01 – Month
- 05 – Day
You can sort it as follows:
ls -lu | grep --color=auto '2006-01-05' |
find Command Example
If you need a specific date range many days ago, than consider using the find command. In this example find files modified between Jan/1/2007 and Jan/1/2008, in /data/images directory:
touch --date "2007-01-01" /tmp/start touch --date "2008-01-01" /tmp/end find /data/images -type f -newer /tmp/start -not -newer /tmp/end |
You can save list to a text file called output.txt as follows:
find /data/images -type f -newer /tmp/start -not -newer /tmp/end > output.txt |
List ALL *.c File Accessed 30 Days Ago
Type the following command
find /home/you -iname "*.c" -atime -30 -type -f |
See also:
- See -atime and -mtime FAQ for more information.
You need to use the find command. Each file has three time stamps, which record the last time that certain operations were performed on the file:
[a] access (read the file’s contents) – atime
[b] change the status (modify the file or its attributes) – ctime
[c] modify (change the file’s contents) – mtime
You can search for files whose time stamps are within a certain age range, or compare them to other time stamps.
You can use -mtime option. It returns list of file if the file was last accessed N*24 hours ago. For example to find file in last 2 months (60 days) you need to use -mtime +60 option.
- -mtime +60 means you are looking for a file modified 60 days ago.
- -mtime -60 means less than 60 days.
- -mtime 60 If you skip + or – it means exactly 60 days.
So to find text files that were last modified 60 days ago, use
$ find /home/you -iname "*.txt" -mtime -60 -print
Display content of file on screen that were last modified 60 days ago, use
$ find /home/you -iname "*.txt" -mtime -60 -exec cat {} \;
Count total number of files using wc command
$ find /home/you -iname "*.txt" -mtime -60 | wc -l
You can also use access time to find out pdf files. Following command will print the list of all pdf file that were accessed in last 60 days:
$ find /home/you -iname "*.pdf" -atime -60 -type -f
List all mp3s that were accessed exactly 10 days ago:
$ find /home/you -iname "*.mp3" -atime 10 -type -f
There is also an option called -daystart. It measure times from the beginning of today rather than from 24 hours ago. So, to list the all mp3s in your home directory that were accessed yesterday, type the command
$ find /home/you -iname "*.mp3" -daystart -type f -mtime 1
Where,
- -type f – Only search for files and not directories
-daystart option
The -daystart option is used to measure time from the beginning of the current day instead of 24 hours ago. Find out all perl (*.pl) file modified yesterday, enter:
find /nas/projects/mgmt/scripts/perl -mtime 1 -daystart -iname "*.pl" |
You can also list perl files that were modified 8-10 days ago, enter:
To list all of the files in your home directory tree that were modified from two to four days ago, type:
find /nas/projects/mgmt/scripts/perl -mtime 8 -mtime -10 -daystart -iname "*.pl" |
-newer option
To find files in the /nas/images directory tree that are newer than the file /tmp/foo file, enter:
find /etc -newer /tmp/foo |
You can use the touch command to set date timestamp you would like to search for, and then use -newer option as follows
touch --date "2010-01-05" /tmp/foo # Find files newer than 2010/Jan/05, in /data/images find /data/images -newer /tmp/foo |
Read the man page of find command for more information:
man find