无
分类: LINUX
2010-06-05 09:58:37
1.shell程序源码:connect.sh
#!/bin/bash
#connect.sh
path="/home/savant/mywork/proj/updown" #所放程序的目录
#define input function
notes()
{
echo "快速上网说明:"
echo "输入r或s连接网络并打开浏览器。"
echo "输入e或q关闭网络和浏览器。"
echo "输入c或clear刷新屏幕。"
echo "选择输入:"
echo "------------------------"
}
notes #call input function
read chioce
while true
do
case $chioce in
r|s)
ifup ppp0 & #up
$path/nap 2
opera &
echo "正在为您加载,请稍候..."
$path/nap 2;; #browser
e|q)
ifdown ppp0
killall -9 opera #down
echo "正在关闭..."
$path/nap 1
exit 1;;
c|clear)
echo "正在刷新..."
$path/nap 1
clear;;
*)
echo "输入出错,请重新输入!"
$path/nap 1;;
esac
clear
notes
read chioce
done
echo "exit"
exit 0
编辑好后增加其执行权限。chmod u+x connect.sh
2.延时1s,2s的c程序源码:nap.c
#include
#include
#include
#include
#define DEBUG 0 /*调试开关*/
#if DEBUG
#define DEBUG_PRINT(time) printf("sleep:%d second.\n",time)
#else
#define DEBUG_PRINT(time)
#endif
int main(int argc,char *argv[])
{
if (argc != 2)
exit(1);
if ((strcmp(argv[1],"1")) == 0) {
DEBUG_PRINT(1);
sleep(1);
}
if ((strcmp(argv[1],"2")) ==0) {
DEBUG_PRINT(2);
sleep(2);
}
return 0;
}
3.编译C程序用的Makefile
CC=gcc
LD=gcc
CFLAGS=-c -Wall -O -g
LDFLAGS=-o
TARGET=nap#生成所需的nap二进制目标文件名
SRCS=$(wildcard *.c)
OBJS=$(patsubst %c,%o,$(SRCS))
.PHONY:all clean
all:$(TARGET)
$(TARGET):$(OBJS)
$(LD) $(LDFLAGS) $(TARGET) $^
#-o 选项之后应该加上生成的最终目标名,再接上所需的目标文件
#例如:gcc -o myapp abc.o bcd.o,不然出错了还难于发现
%.o:%.c
$(CC) $(CFLAGS) $<
clean:
rm -f *.o $(TARGET)
4.本文是linux下用opera浏览器发的日志,代码粘贴后就没有了缩进,没有时间更改,请网友们谅解!