GNU bash,版本1.14.7(1)
我有一个脚本被称为" abc.sh"我必须从abc.sh脚本中检查这个...在其中我写了以下语句
status=`ps -efww | grep -w "abc.sh" | grep -v grep | grep -v $$ | awk '{ print $2 }'`
if [ ! -z "$status" ]; then
echo "[`date`] : abc.sh : Process is already running"
exit 1;
fi
Run Code Online (Sandbox Code Playgroud)
我知道这是错的,因为每次它退出,因为它在'ps'中找到了自己的进程如何解决它?如何检查脚本是否已经运行from that script?
Os:REDHAT LINUX Linux管理:2.6.18.8-1#
这是否可以直接从NIC读取MAC地址?我有下面的代码,但它只是从上面的层读取,但不是卡本身!
我试图弄清楚如何在我的linux机箱上找到以太网NIC的原始MAC地址.我知道如何找到用ifconfig当前的MAC地址,但如果该地址已更改,比如说使用
'ifconfig eth0 hw ether uu:vv:ww:yy:xx:zz',或者我设置"永久"使用它vi /etc/sysconfig/network-scripts/ifcfg-eth0.这个文件......我可以成功地UP它REBOOT也.我怎么找原件?必须有一种方法来找到它,因为它仍然永久地刻录到卡中,但我找不到一个工具来读取刻录的地址.它有什么用途或命令吗?我想为它编写C代码.但在上述情况下不知道如何做到这一点.
**下面的代码给出了我当前的 MAC但不是原始的MAC
#include <stdio.h> /* Standard I/O */
#include <stdlib.h> /* Standard Library */
#include <errno.h> /* Error number and related */
#define ENUMS
#include <sys/socket.h>
#include <net/route.h>
#include <net/if.h>
#include <features.h> /* for the glibc version number */
#if __GLIBC__ >= 2 && __GLIBC_MINOR >= 1
#include <netpacket/packet.h>
#include <net/ethernet.h> /* the L2 protocols */
#else
#include <asm/types.h>
#include <linux/if_packet.h> …Run Code Online (Sandbox Code Playgroud) rm -rf /etc/XXX.pid当shell脚本在执行过程中被中断时,我想发出像" " 这样的命令.喜欢使用CTRL+C
任何人都可以帮我在这做什么?
我是C编程的新手.我对.so文件一无所知.有什么需要呢?我怎么创建它?如何绑定我的C代码或二进制文件?如果我不制作任何.so文件并直接生成C代码的可执行二进制文件,它的PROS和CONS是什么?需要详细描述它.
我有一个主要功能,
int main (int argc, char **argv)
{}
Run Code Online (Sandbox Code Playgroud)
我应该传递两个不同的命令行参数:
argv[1]=IP ADDRESS type
argv[2]=INTEGER type
Run Code Online (Sandbox Code Playgroud)
例如,./a.out IP-ADDRESS INTEGER.我用其他一些脚本调用这个二进制文件.
问题是虽然argv[1]不可用,但它的行为与INTEGER价值一样argv[1].
我怎样才能检查一下,如果argv是类型INT不进入argv[1]或只IP-ADDRESS允许类型argv[1]?
function syncfile(){
echo "[ DONE $file ]"
return ;
}
function syncfolder(){
folder=$1
for foo in `ls -1 $folder`
do
file="$folder/$foo"
if [ -d $file ];then
syncfolder $file
elif [ -e $file ];then
syncfile $file
else
echo "$file is neither file nor directory"
fi
done
return;
}
Run Code Online (Sandbox Code Playgroud)
上面是我的两个递归函数..当我调用syncfolder $foldername它时, 在下面的情况下没有给出正确的输出..
假设层次结构如下所示
portchanges/
portchanges/script/script1/script1.sh
portchanges/script/script1/script2.sh
portchanges/script/script1/script3.sh
portchanges/script/script4.sh
portchanges/script/script5.sh
portchanges/script6.sh
portchanges/script7.sh
portchanges/appl/script11/script11.sh
portchanges/appl/script11/script12.sh
portchanges/appl/script11/script13.sh
Run Code Online (Sandbox Code Playgroud)
现在如果foldername=portchanges
和我打电话syncfolder $foldername
它仅用于处理
portchanges/script/script1/script1.sh
portchanges/script/script1/script2.sh
portchanges/script/script1/script3.sh
Run Code Online (Sandbox Code Playgroud)
与function syncfile()函数调用...然后它去return的syncfolder …
bash ×3
linux ×3
shell ×3
c ×2
sh ×2
argc ×1
argv ×1
concurrency ×1
linux-kernel ×1
mac-address ×1
sockets ×1
unix ×1