ギャバンITサービス
お菓子の家が作れるシステムエンジニアです

centOS6のサービス設定

initデーモン linuxサーバが起動したときにスクリプトを実行するためには、 以下のフォルダにスクリプト実行用シェルがあるため、 そこに登録しておく。 /etc/rc.d/rc3.d/ S01からS99の順番に起動されていくが、S99localというシェルに書き込んでおくと、すべての処理が動いた最後に起動される。 呼び出し 以下、登録例。 1 2 3 4 5 6 7 8 9 [root@saturn rc3.d]# cat S99local #!/bin/sh # # This script will be executed *after* all the other init scripts. # You can put your own initialization stuff in here if you don't # want to do the full Sys V style init stuff. touch /var/lock/subsys/local /bin/sh /takara/tkr_script/006_EtherReset.sh > /dev/null 参考URL

kshってaixで使ったかも

ファイル読み込み 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #!/bin/ksh #入力ファイル名 INPUTFILE="./input.txt" #入力ファイルの区切り文字 IFS=","; #ファイル読み込み while read line ; do if [[ "$line" != "" ]] then set $line echo "[$1][$2]" fi done < ${INPUTFILE} case文 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 OSNAME=$(uname) case $OSNAME in Linux) dmesg > $SYSLOG_OUTFILE ;; # not supported iostat COMMAND SunOS) dmesg > $SYSLOG_OUTFILE IOOPT=-x ;; HP-UX) alias pscmd="ps -ef" alias dfcmd="bdf" IOOPT=-t ;; AIX) alias pscmd="ps -e -o user,pid,ppid" IOOPT=-d ;; *) echo "Not support $OSNAME.";exit 3 ;; esac for文 1 2 3 4 5 RESULT=/tmp/res.out for ARG in "$@" do echo $ARG done > RESULT 2>&1 while文 1 2 3 4 5 6 7 let n=0 while read line do let n=$n+1 echo "$n: $line" done < $0 echo "Total lines are $n ." while無限 1 2 3 while true; do sleep 60 done OSコマンド実行 1 2 3 4 5 6 7 set -A DIR_NMS $(ls) : DIR_NMS 配列に `ls` の結果 MAX_DIR=${#DIR_NMS[*]} : MAX_DIR に ls の個数 ただしファイル数が多い場合、配列がオーバーフローしエラー 配列の最大サイズは 1024 です。 alias datecmd='date +"%Y %m %d"' TODAY=$(datecmd) 演算子 演算子 意味 例:let no=6 結果 exp1 -eq exp2 exp1 と exp2 が等しいなら真 if [[ $no -eq 6 ]];then echo YES;fi; YES exp1 -ne exp2 exp1 と exp2 が等しくないなら真 if [[ $no -ne 6 ]];then echo NO;fi; exp1 -lt exp2 exp1 < exp2 なら真 if [[ $no -lt 6 ]];then echo NO;fi; exp1 -gt exp2 exp1 > exp2 なら真 if [[ $no -gt 6 ]];then echo NO;fi; exp1 -le exp2 exp1 <= exp2 なら真 if [[ $no -le 6 ]];then echo YES;fi; YES exp1 -ge exp2 exp1 >= exp2 なら真 if [[ $no -ge 6 ]];then echo YES;fi; YES 文字列検査演算子 演算子 意 味 例:str=“oracle”;str1=“AZ”;str2=“BZ” 結果 -n string string の長さがゼロでなければ真 if [[ -n $str ]];then echo YES;fi; YES -o option option が設定されていれば真 if [[ -o $str ]];then echo NO;fi; -z string string の長さがゼロならば真 if [[ -z $str ]];then echo NO;fi; YES string = pattern string と pattern が一致すれば真 if [[ $str = “oracle” ]];then echo YES;fi; YES string != pattern string と pattern が一致しなければ真 if [[ $str != “oracle” ]];then echo NO;fi; string1 < string2 string1 < string2 なら真 if [[ $str < “ORACLE” ]];then echo NO;fi; string1 > string2 string1 > string2 なら真 if [[ $str > “ORACLE” ]];then echo YES;fi; YES (expression) expression が真なら真 if [[ ($str = [a-z]*) ]];then echo YES;fi; YES ! expression expression が偽なら真 if [[ ! ($str = [A-Z]*) ]];then echo YES;fi; YES exp1 && exp2 exp1 と exp2 が真なら真 if [[ ($str1 = [A-Z]*) && ($str2 = [A-Z]*) ]];then echo YES;fi; YES exp1 || exp2 exp1 か exp2 が真なら真 if [[ ($str1 = “AZ”) || ($str2 = “AZ”) ]];then echo YES;fi; YES ファイル検査演算子 演算子 真となる条件 例 結果 -a file ファイルは存在する if [[ -a $HOME/.cshrc ]];then echo YES;fi YES -b file ファイルは存在し、ブロック型である if [[ -b /dev/null ]];then echo YES;fi -c file ファイルは存在し、文字型である if [[ -c /dev/stdin ]];then echo YES;fi YES -d file ファイルはディレクトリ if [[ -d $HOME ]];then echo YES;fi YES -f file ファイルは普通のファイル if [[ -f $HOME/.cshrc ]];then echo YES;fi YES -g file ファイルは存在し、setgid が設定されている if [[ -g $HOME/.cshrc ]];then echo YES;fi -k file ファイルは存在し、sticky が設定されている if [[ -k /opt/SWAP ]];then echo YES;fi -p file ファイルは存在し、fifo である if [[ -p /tmp/.X11-pipe/X0 ]];then echo YES;fi -r file ファイルをユーザが読める if [[ -r $HOME/.cshrc ]];then echo YES;fi YES -s file ファイルは存在し、0 より大きい if [[ -s $HOME/.cshrc ]];then echo YES;fi YES -t N ファイルディスクリプタ N が端末である if [[ -t 1 ]];then echo YES;fi YES -u file ファイルは存在し、setuid が設定されている if [[ -u $HOME/.cshrc ]];then echo YES;fi YES -w file ファイルは存在し、ユーザが書ける if [[ -w $HOME/.cshrc ]];then echo YES;fi YES -x file ファイルは存在し、ユーザが実行できる if [[ -x /bin/ksh ]];then echo YES;fi YES -G file ファイルは存在し、グループ id はシェル と同じ if [[ -G $HOME/.cshrc ]];then echo YES;fi YES -L file ファイルは存在し、シンボリックリンクである if [[ -L /usr/lib/libcrypt.so ]];then echo YES;fi YES -O file ユーザはファイルの所有者 if [[ -O $HOME/.cshrc ]];then echo YES;fi YES -S file ファイルは存在し、ソケットである if [[ -S /var/tmp/.oracle/sora817 ]];then echo YES;fi YES F1 -nt F2 ファイルは存在し、F2 より新しい if [[ .cshrc -nt $HOME/.cshrc ]];then echo YES;fi YES F1 -ot F2 ファイルは存在し、F2 より古い if [[test.c -ot test.o ]];then echo YES;fi YES F1 -ef F2 ファイルは存在し、ファイルが同じファイルを参照 if [[ /usr/lib/libcrypt.so -ef /lib/libcrypt.so.1 ]];then echo YES;fi YES メタ文字 メタ文字 意 味 例 ~ ホームディレクトリ cd ~taka $ 変数識別子 $HOME $! 直前に呼び出した子プロセスの番号 kill $! $- シェルに与えられたフラグ <,>,&,! 入出力の切換え echo $HOME > /tmp/out !,^ 履歴 !vi $$ 起動中のシェルのプロセス番号 set out=/tmp/$$.out ; コマンド区切り cd;pwd () コマンドグループ (cd; make) コマンド コマンド置き換え set file = ls & バックグラウンドジョブ tst & ,’," 文字をエスケープする echo ‘$HOME’ \ 次文字をエスケープする echo \$HOME 継続行であることを示す。前に空白が必要 XXXXXXX \ *,?,[,],,{,},|,~,- ファイル名展開 ls t?.* 文字として扱いたい場合はエスケープ () # コメント | パイプ ls | more

linuxファイルシステムの操作

パーティションの確認と作成 fdiskでいいけど2TBを超える大きなファイルシステムはgparted使う。 パーティション情報の表示やってみる。 1 2 3 4 5 6 7 8 9 10 11 12 13 # fdisk -l /dev/sda Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x6144fea0 Device Boot Start End Sectors Size Id Type /dev/sda1 * 2048 1050623 1048576 512M b W95 FAT32 /dev/sda2 1052670 209713151 208660482 99.5G 5 Extended /dev/sda5 1052672 209713151 208660480 99.5G 83 Linux # パーティションのタイプを設定していく。 ...

centOS6の自動ログイン

自動ログインの設定がCentOS5で出来ていたものがCentOS6ではできなくなったのを何とかする 1 2 3 4 5 6 7 /etc/gdm/custom.conf [daemon] TimedLoginEnable=true TimedLogin=nari TimedLoginDelay=5 [...] centos6にvmware player入れてwindows環境を動かしてたときに使ってた。 ubuntu18/20では別の方法で実施。

selinux無効化

DMZにサーバ立てるときは使うかもしれないけど、ローカルサーバにはとても邪魔なselinux。 redhat/centosではほぼ即時で無効化してた。 状態を確認 1 2 $ getenforce Enforcing 無効化 1 2 3 # setenforce 0 # getenforce Permissive 無効化をずっと /etc/sysconfig/selinuxの設定を以下のように書き換える。 SELINUX=disabled