作者 主題: shell script question  (閱讀 2395 次)

0 會員 與 1 訪客 正在閱讀本文。

ahlek

  • 懷疑的國中生
  • **
  • 文章數: 53
    • 檢視個人資料
shell script question
« 於: 2002-12-07 19:53 »
i want do a shell script connect to mysql to get some information on the user. and write it to the user /home/xxx/.test

e.g
in mysql got keep track all the users information like home address,telphone number,
so how do i writing a script connect to mysql get this kind of information and write to a file in each user /home/xxx/.test so then when each user login that time it can show the detail .test in their motd.
) ^-^ ^_^

netman

  • 管理員
  • 俺是博士!
  • *****
  • 文章數: 17472
    • 檢視個人資料
    • http://www.study-area.org
shell script question
« 回覆 #1 於: 2002-12-07 22:25 »
sorry i am not good at mysql at all.

so, could you tell me how you do the jobs in command lines?
once you can achieve datas manually, then you can got them in a script.

ahlek

  • 懷疑的國中生
  • **
  • 文章數: 53
    • 檢視個人資料
shell script question
« 回覆 #2 於: 2002-12-11 18:15 »
ok..how about if i got save all the user file in user.txt

then is it possible i can using shells script to read user.txt file
and create a simply test.txt in each user direcotry /home/xxx ???

the user.txt <--have all the user information .

e.g
user.tx
---------
login:ahlek
tel:003
address:testing

login:test
tel:004
address:test2

so i using shell script to create a file in /home/ahlek/test.txt
and this test.txt only got ahlek user detail
/home/ahlek/test.txt
--------
tel:003
address:testing

/home/test/test.txt
tel:004
address:test2

is it possible ??
) ^-^ ^_^

netman

  • 管理員
  • 俺是博士!
  • *****
  • 文章數: 17472
    • 檢視個人資料
    • http://www.study-area.org
shell script question
« 回覆 #3 於: 2002-12-11 23:39 »
grep -A2 "login:$USER" user.tx  | tail +2 > $HOME/test.txt

ahlek

  • 懷疑的國中生
  • **
  • 文章數: 53
    • 檢視個人資料
shell script question
« 回覆 #4 於: 2002-12-12 09:32 »
引述: "netman"
grep -A2 "login:$USER" user.tx  | tail +2 > $HOME/test.txt


To:netman
i have try grep -A2 "login:$USER" user.tx  | tail +2 >$HOME/test.txt
it wont work.. but if
grep -A2 "login:$USER" user.tx  | >/$home/test.txt
then it work..

but i have another question.
let say i wan using root to running while loop. auto
writing in each user folder . how can i do ?
sorry.i dont know much shell script one.
it means the $user <--i wan set variable how can i do ??

tks again
) ^-^ ^_^

netman

  • 管理員
  • 俺是博士!
  • *****
  • 文章數: 17472
    • 檢視個人資料
    • http://www.study-area.org
shell script question
« 回覆 #5 於: 2002-12-12 11:30 »
$USER is different to $user,
same for $HOME and $home....

also, /$HOME is different to $HOME too.