2014年11月20日 星期四

linux signal相關設定

目前在寫daemon,
寫到了處理signal的程式

signal (SIGHUP, sighup_handler);
表示當這一個process收到一個SIGHUP時,
sighup_handler這一個函式會被執行。

SIGHUP
一般是用在參考檔案更新時。

可以直接透過下指令去驗証此function是否正常
kill -HUP 3077
killall -HUP a.out

SIGTERM, SIGINT


參考資料:
Sending signal to Processes
signal 小知識
Daemon函数的用法
寫 linux daemon 的注意事項

2014年11月17日 星期一

建立samba

因為compiler環境在linux,
而產生出來的image檔案必需要傳到windows上做燒錄的動作。

找了一下,有幾個方式可以完成,
FTP
WEB
網路芳鄰

目前看起來最簡單的方式應該是網路芳鄰samba

在多天的嘗試後,可以正常的使用帳號的方式連線到linux的空間,
可惜的是還沒有辦法試成功可以用匿名的方試登入(Guest)

========== 開始 ==========
0. 查詢是否有安裝samba
rpm -q samba

1. 查詢防火牆的狀態
systemctl status firewalld

2. 關掉防火牆
systemctl disable firewalld
systemctl stop firewalld

3. 新增samba使用者
smbpasswd -a caspar
若遇到以下錯誤訊息,表示系統沒有相對應的帳號。
目前的設置是linux系統有的帳號,samba才可以追加其帳號。

4. 停用samba使用者
smbpasswd -d caspar

5. 刪除samba使用者
smbpasswd -x caspar

6. 啟用samba服務
service smb start

7. 重新啟動samba服務
service smb restart

8. 查詢目前samba的狀態
service smb status

基本上新增samba使用者後,就可以由windows進入,但是,目前成功的方試,仍然要使用帳號跟密碼。

smbpasswd這一個指令可以做一些簡單的使用者帳號的操作,
但是更深入的操作方式就必需要使用pdbedit這一個指令

========== pdbedit 指令說明 ==========
pdbedit -L
列出使用者列表

pdbedit -Lv
列出詳細的使用者列表

pdbedit -Lw
列出同 smbpasswd 格式的使用者列表

pdbedit -a jerry
新增 jerry帳號

pdbedit -x jerry
刪除 jerry帳號

pdbedit -c "[D]" -u jerry
暫時停用 jerry 這個帳號

pdbedit -c "[]" -u jerry
恢復使用 jerry 這個帳號

========== 其它資訊 ==========
linux上登入window或是samba的電腦
smbclient //主機/分享的資料匣資源 -U 使用者名稱
輸入密碼就可以執行類似ftp的指令了

mount 別台機器分享的資源到本台電腦
mount -t smbfs -o username=使用者名稱 ,password=密碼 //主機名稱/分享的資源 /主機目錄

查詢使用的port
netstat -anp

查詢目前執行的程式
ps aux | grep mbd

在設定smb.conf時, 若嘗試要設定Guest登入
設定security為share
會出現以下錯誤
WARNING: Ignoring invalid value 'share' for parameter 'security'
改為以下就可以正常的
security = user
map to guest = Bad User

========== 自己安裝 samba-4.1.13 ==========
./configure
會出現以下錯誤訊息
Could not find the python development headers
安裝以下套解可以解除問題
yum install libacl-devel libblkid-devel gnutls-devel readline-devel python-devel gdb pkgconfig

參考資料:
如何檢查linux中的服務是否正常?
Samba 設定USER等級分享目錄[3]
Samba 下 Ubuntu與Win7共享資料夾設定,利用 host-only網路
Samba-4.1.13
安裝samba系統
fedora 10/11 安裝samba || windows 與 linux 的網芳設定
第十六章、檔案伺服器之二: SAMBA 伺服器

windows 網路指令

arp
可以查詢IP與MAC相對應的列表

arp -s 157.55.85.212 00-aa-00-62-c6-09 .... 新增靜態項目。
arp -a .... 顯示 ARP 表格。

2014年11月3日 星期一

daemon




參考資料:
寫 linux daemon 的注意事項

2014年10月30日 星期四

取得IPv6 address


參考資料:
get-ipv6-addr.c - Source file - www-user

sscanf使用心得


參考資料:
C 語言中的 sscanf() 函數

linux script

1. 判斷檔案是否存在

#!/bin/bash
file="/etc/hosts"
if [ -f "$file" ]
then
  echo "$file found."
else
  echo "$file not found."
fi

       -b FILE
              FILE exists and is block special
       -c FILE
              FILE exists and is character special
       -d FILE
              FILE exists and is a directory
       -e FILE
              FILE exists
       -f FILE
              FILE exists and is a regular file
       -g FILE
              FILE exists and is set-group-ID
       -G FILE
              FILE exists and is owned by the effective group ID
       -h FILE
              FILE exists and is a symbolic link (same as -L)
       -k FILE
              FILE exists and has its sticky bit set
       -L FILE
              FILE exists and is a symbolic link (same as -h)
       -O FILE
              FILE exists and is owned by the effective user ID
       -p FILE
              FILE exists and is a named pipe
       -r FILE
              FILE exists and read permission is granted
       -s FILE
              FILE exists and has a size greater than zero
       -S FILE
              FILE exists and is a socket
       -t FD  file descriptor FD is opened on a terminal
       -u FILE
              FILE exists and its set-user-ID bit is set
       -w FILE
              FILE exists and write permission is granted
       -x FILE
              FILE exists and execute (or search) permission is granted

參考資料:
Bash Shell: Check File Exists or Not