Http://bbs.chinaunix.net/viewthread.php? Tid = 133502
Cygwin has just been installed. It is very interesting to think of it as a testing environment for company operators. However, because cygwin does not have logon or other operations, it has only the most basic functions to write scripts such as Su. The following is a program script, which takes a short time. In addition, the younger brother shell is just getting started. I hope all the bosses can give me some suggestions to remove the insects. The younger brother will thank you first.
First, change the default. bash_profile:
Echo-e "\ n select the system to enter: \ n"
Echo-e "(1) system1 \ n"
Echo-e "(2) system2 \ n"
Echo-e "(*) Exit \ n"
Echo-e "your choice: \ c"
Read choice
Case "$ choice" in
1) Clear
Exec/home/admin/bin/mylogin/etc/passwd.1 ;;
2) Clear
Exec/home/admin/bin/mylogin/etc/passwd.2
;;
*) Exit
;;
Esac
The following is passwd .? Format (no permission is set, so it doesn't matter if the password is not encrypted ):
Username, password, home, Shell, path, Profile
Mylogin script:
If [$ #-ne 1]
Then
Exit
Fi
Passfile = $1
Trap "" 2 3 15
I = 1
While [$ I-le 3]
Do
Echo-n "login :"
Read Username
Stty-echo
Echo-n "Password :"
Read Password
Stty echo
Echo-e "\ n \ c"
Chkuser = 'grep "$ username" $ {passfile} | WC-l'
If [$ chkuser-ne 1]
Then
Echo "UX: login: Error: Login incorrect"
Else
Userpasswd = 'grep "$ username" $ {passfile} | awk-F, '{print $2 }''
If ["$ password" = "$ userpasswd"]
Then
PS1 = "\ $"
Home = 'grep "$ username" $ {passfile} | awk-F, '{print $3} ''; Export Home
Path = 'grep "$ username" $ {passfile} | awk-F, '{print $5} ''; export path
CD $ home
Profile = 'grep "$ username" $ {passfile} | awk-F, '{print $6 }''
If [-F $ home $ Profile]
Then
. $ Home $ Profile
Fi
Usershell = 'grep "$ username" $ {passfile} | awk-F, '{print $4} ''; export usershell
$ Usershell-I
I = 3
Else
Echo "UX: login: Error: Login incorrect"
Fi
Fi
I = 'expr $ I + 1'
Done
In this way, you can add users in passwd, log on to your directory, and use your own environment variables, but Su is not available, so you have compiled a simple one:
Passfile =/etc/passwd.1
If ["$1 "! = "-"]
Then username = $1
Envchg = 0
Else username = $2
Envchg = 1
Fi
Chkuser = 'grep -- "$ username" $ {passfile} | WC-l'
If [$ chkuser-ne 1]
Then
Echo "UX: su: Error: Unknown user ID: $ username"
Exit
Else
Stty-echo
Echo-n "Password :"
Read Password
Stty echo
Echo-e "\ n \ c"
Userpasswd = 'grep "$ username" $ {passfile} | awk-F, '{print $2 }''
If ["$ password" = "$ userpasswd"]
Then
If [$ envchg-EQ 1]
Then
Home = 'grep "$ username" $ {passfile} | awk-F, '{print $3} ''; Export Home
Path = 'grep "$ username" $ {passfile} | awk-F, '{print $5} ''; export path
CD $ home
Profile = 'grep "$ username" $ {passfile} | awk-F, '{print $6 }''
If [-F $ home $ Profile]
Then
. $ Home $ Profile
Fi
Fi