unix

Ubuntu学习总结-08 Ubuntu运行Shell脚本报 shell /bin/bash^M: bad interpreter错误问题解决

▼魔方 西西 提交于 2020-02-25 11:45:45
  错误原因之一很有可能是运行的脚本文件是DOS格式的, 即每一行的行尾以\r\n来标识, 其ASCII码分别是0x0D, 0x0A. 可以有很多种办法看这个文件是DOS格式的还是UNIX格式的, 还是MAC格式的 (1). vi filename 然后用命令 :set ff? 可以看到dos或unix的字样. 如果的确是dos格式的, 那么你可以用set ff=unix把它强制为unix格式的, 然后存盘退出. 再运行一遍看. (2). 用joe filename 如果是DOS格式的, 那么行尾会有很多绿色的^M字样出现. 你也可以用上述办法把它转为UNIX格式的. (3). 用od -t x1 filename 如果你看到有0d 0a 这样的字符, 那么它是dos格式的, 如果只有0a而没有0d, 那么它是UNIX格式的, 同样可以用上述方法把它转为UNIX格式的. 转换不同平台的文本文件格式可以用 1. unix2dos或dos2unix这两个小程序来做. 很简单. 在djgpp中这两个程序的名字叫dtou和utod, u代表unix, d代表dos 2. 也可以用sed 这样的工具来做: sed 's/^M//' filename > tmp_filename mv -f tmp_filename filename 来做 说明:^M并不是按键shift + 6产生的

UNIX环境高级编程--10. 信号

ぐ巨炮叔叔 提交于 2020-02-24 23:19:48
第十章 信号 信号是软中断,提供了一种处理异步事件的方法。例如,终端用户键入终端键,会通过信号机制停止一个进程, 或及早终止管道中的下一个程序。 每个信号都有一个名字,SIG开头。例如: SIGABRT:夭折信号,当进程调用abort函数时产生。 SIGALRM:闹钟信号,由alarm函数设定时器超时后将产生此信号。 当信号出现时,可以告诉内核按下列三种方式之一进行处理: (1)忽略此信号。butSIGKILL和SIGSTOP不能忽略。他们向内核和超级用户提供了使进程终止或停止的可靠方法。另外,硬件异常产生的信号也不能忽略。 (2)捕捉信号。 (3)执行系统默认动作。 函数signal: UNIX系统信号机制最简单的接口是signal函数。 void (*signal (int signo, void (*func)(int))) (int); 返回值:成功,返回以前的信号处理配置;出错,返回SIG_ERR。 signo信号名(SIGABRT等); func取值可以是: 常量SIG_IGN 表示忽略此信号 常量SIG_DFL 表示接到此信号后动作是系统默认动作 函数地址 信号发生时,调用该函数。 函数kill和raise: kill和raise函数用来发送信号。 kill函数将信号发送给进程或进程组。raise函数则允许进程向自身发送信号。 调用 raise(signo);

Unix时间戳转换怎样在Excel批量修改?

北慕城南 提交于 2020-02-22 21:03:38
  最近在操作项目的时候碰到一个Unix时间戳转换的问题。 "date_time":1393031347 这个是什么,你知道吗?如果你对Unix时间戳了解的话一眼就看出来。但我们本着科普的理念稍微介绍一下,大神请飘过。   看到 date_time ,我们第一反应就是日期时间,但是后面的一串数字什么意思天才晓得!我们是好学的孩子,不能做那么不负责的事情,不懂就找度娘,虽然度娘已经出走了。搜索了一下,大部分结果是说用不同编程语言进行datetime转换,比如java、perl、php等,虽然略知一二,但要写一个时间戳转换程序尔等小民高不可攀,而且时间成本太高了。   继续search,总算知道了那串数字是unix时间戳。现在局势有些好转了,知其然不知其所以然那是不可能的,通过你的努力"所以然"很快就要显现人间了。很多站长工具都有 Unix时间戳(Unix timestamp)转换工具 ,但是那些只能一次转换一个。一大列时间戳够你整一个月的。   工欲善其事必先利其器!Excel批量操作数据是个不错的选择。那就开工了!Excel默认不支持Unix格式时间戳,但前辈们早就为我们考虑到了。可以用以下公式将时间戳转换成Excel格式的时间:=(x+8*3600)/86400+70*365+19,如果不行换成=(x+8*3600)/86400+66*365+19   怎么样

python中os模块中文帮助

佐手、 提交于 2020-02-22 02:22:24
python中os模块中文帮助文档 文章分类:Python编程 python中os模块中文帮助文档 翻译者:butalnd 翻译于2010.1.7——2010.1.8,个人博客: http://butlandblog.appspot.com/ 注此模块中关于unix中的函数大部分都被略过,翻译主要针对WINDOWS,翻译速度很快,其中很多不足之处请多多包涵。 这个模块提供了一个轻便的方法使用要依赖操作系统的功能。 如何你只是想读或写文件,请使用open() ,如果你想操作文件路径,请使用os.path模块,如果你想在命令行中,读入所有文件的所有行,请使用 fileinput模块。使用tempfile模块创建临时文件和文件夹,更高级的文件和文件夹处理,请使用shutil模块。 os.error 内建OSError exception的别名。 os.name 导入依赖操作系统模块的名字。下面是目前被注册的名字:'posix', 'nt', 'mac', 'os2', 'ce', 'java', 'riscos'. 下面的function和data项是和当前的进程和用户有关 os.environ 一个mapping对象表示环境。例如,environ['HOME'] ,表示的你自己home文件夹的路径(某些平台支持,windows不支持) ,它与C中的getenv("HOME")一致。

using sed, remove everything before the first occurence of a character

。_饼干妹妹 提交于 2020-02-21 13:48:12
问题 Let's say I have a line looking like this Hello my first name is =Bart and my second is =Homer How can I do if I want to get everything after the first = or : using sed ? In this example, I would like to get the result Bart and my second is =Homer I am using sed 's/.*[=:]//' right now but I get Homer as result (everything after the last = or : ) and I would like to get everything after the first, and not the last = or : 回答1: Normally, quantifiers in sed are greedy, which is why you will

using sed, remove everything before the first occurence of a character

寵の児 提交于 2020-02-21 13:45:12
问题 Let's say I have a line looking like this Hello my first name is =Bart and my second is =Homer How can I do if I want to get everything after the first = or : using sed ? In this example, I would like to get the result Bart and my second is =Homer I am using sed 's/.*[=:]//' right now but I get Homer as result (everything after the last = or : ) and I would like to get everything after the first, and not the last = or : 回答1: Normally, quantifiers in sed are greedy, which is why you will

Why was SIGFPE used for integer arithmetic exceptions?

倖福魔咒の 提交于 2020-02-21 10:57:45
问题 Why was SIGFPE used for integer arithmetic exceptions, such as division by zero, instead of creating a separate signal for integer arithmetic exceptions or naming the signal in the first place for arithmetic exceptions generally? 回答1: IEEE Std 1003.1 Standard defines SIGFPE as: Erroneous arithmetic operation. And doesn't really mention floating point operations. Reasoning behind this is not clearly stated, but here's my take on it. x86 FPU can operate on both integer and floating point data

Rootkit 真刀真枪的权限保卫战

本秂侑毒 提交于 2020-02-19 07:08:01
Rootkit 真刀真枪的权限保卫战 作者:小珂 通常,我们在获得了对目标的控制权后,还想保持这种控制权限,于是就出现了木马后门,Rootkit之类的保护权限的手段。首先来说一下我们常见的应用层次的木马后门,比如我们常见的远程控制类的软件,像国外的Sub7,VNC,netbus,国内的冰河,灰鸽子,黑洞等等,这些大家都很熟悉就不详细介绍了。此类后门很容易被发现,现在的杀毒软件大多都能轻松的查杀,即使暂时查不到,用其它手段检测发现也不困难,而这次给大家介绍的是比一般木马后门潜伏的更深木马后门--Rootkit。 传统的Rootkit是一种比普通木马后门更为阴险的木马后门。它主要通过替换系统文件来达到目的,这样就会更加隐蔽,使检测变得比较困难。传统的Rootkit主要针对Unix平台,例如Linux、AIX、SunOs等操作系统,有些Rootkits可以通过替换DLL文件或更改系统来攻击Windows平台。Rootkit并不能让你直接获得权限,相反它是在你通过各种方法获得权限后才能使用的一种保护权限的措施,在我们获取系统根权限(根权限即root权限,是Unix系统的最高权限)以后,Rootkits提供了一套工具用来建立后门和隐藏行迹,从而让攻击者保住权限。 传统Rootkit对Unix的攻击 RootKits是如何实现后门的呢?为了理解Rootkits后门

Parallel processing or threading in Shell scripting

倾然丶 夕夏残阳落幕 提交于 2020-02-17 13:36:31
问题 I am writing a script in shell in which a command is running and taking 2 min. everytime. Also, there is nothing we can do with this. But if i want to run this command 100 times in script then total time would be 200min. and this will create a big issue. Nobody want to wait for 200min. What i want is to run all 100 commands parallely so that output will come in 2min or may be some more time but dont take 200min. it will be appreciated, if any body can help me on this in any way. 回答1: GNU

Parallel processing or threading in Shell scripting

自古美人都是妖i 提交于 2020-02-17 13:31:12
问题 I am writing a script in shell in which a command is running and taking 2 min. everytime. Also, there is nothing we can do with this. But if i want to run this command 100 times in script then total time would be 200min. and this will create a big issue. Nobody want to wait for 200min. What i want is to run all 100 commands parallely so that output will come in 2min or may be some more time but dont take 200min. it will be appreciated, if any body can help me on this in any way. 回答1: GNU