unix

Extract all variable values in a shell script

混江龙づ霸主 提交于 2020-01-16 14:31:09
问题 I'm debugging an old shell script; I want to check the values of all the variables used, it's a huge ugly script with approx more than 140 variables used. Is there anyway I can extract the variable names from the script and put them in a convenient pattern like: #!/bin/sh if [ ${BLAH} .... ..... rm -rf ${JUNK}..... to echo ${BLAH} echo ${JUNK} ... 回答1: Try running your script as follows: bash -x ./script.bash Or enable the setting in the script : set -x 回答2: You can dump all interested

C/UNIX mmap array of int

泪湿孤枕 提交于 2020-01-16 11:22:21
问题 Is it possible to mmap file full of integeres as integer array? I mean sth like this (which doesn't work) given file tmp.in 1 2 15 1258 and similar code to this int fd; if ((fd = open("tmp.in", O_RDWR, 0666)) == -1) { err(1, "open"); } size_t size = 4 * sizeof(int); int * map = (int *) mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); I'd like to be able call printf("%d\n", map[2]+1); with expected result 16 I found char mapping using sscanf to parse integers, but I need to have

C/UNIX mmap array of int

守給你的承諾、 提交于 2020-01-16 11:21:42
问题 Is it possible to mmap file full of integeres as integer array? I mean sth like this (which doesn't work) given file tmp.in 1 2 15 1258 and similar code to this int fd; if ((fd = open("tmp.in", O_RDWR, 0666)) == -1) { err(1, "open"); } size_t size = 4 * sizeof(int); int * map = (int *) mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); I'd like to be able call printf("%d\n", map[2]+1); with expected result 16 I found char mapping using sscanf to parse integers, but I need to have

Search and Replace ( multiple lines )

拜拜、爱过 提交于 2020-01-16 11:12:30
问题 Hello StackOverflow Community! I'm working on a bash script to change in Dynamic text file, I want to replace multiple lines with one line. Ex: This example, I want to replace THIS CCCCC DDDDD With KKKKK Before script AAAAA CCCCC DDDDD BBBBB CCCCC DDDDD CCCCC After script AAAAA KKKKK BBBBB KKKKK CCCCC I found a script to replace using ( sed ) but it doesn't replace multiple lines. NOTE: I'm a beginner at scripting so please explain how it can be done easy :) 回答1: The sed expression you are

陈皓谈对待技术的态度

一曲冷凌霜 提交于 2020-01-16 08:05:01
最近在 酷壳 上,陈皓撰文阐述了对待技术的态度,如何面对技术的快速更新?是否做软件开发比以前更加困难了?他都给出了自己的见解。 陈皓首先针对“如何看待日新月异的新技术”做出了回答: 遇到新技术我会去了解,但不会把很大的精力放在这些技术(如:NoSQL,Node.js,等)。这些技术尚不成熟,只需要跟得住就可以了。技术十年以上可能是一个门槛。有人说技术更新换代很快,我一点儿都不觉得是这样想。虽然有不成熟的技术不断地涌出,但是成熟的技术,比如Unix,40多年,C,40多年,C++,30多年,TCP/IP,20多年,Java也有将近20年了……,所以,如果你着眼成熟的技术,其实并不多。 他的核心观点是——要了解技术就一定需要了解整个计算机的技术历史发展和进化路线。你要朝着球运动的轨迹去,而不是朝着球的位置去,要知道球的运动轨迹,你就需要知道它历史上是怎么跑的。 然后,他简要回顾了IT技术的脉络,并列出了几条关键的主线: 70年代Unix的出现,是软件发展方面的一个里程碑,那个时期的C语言,也是语言方面的里程碑。(当时)所有的项目都在Unix/C上,全世界人都在用这两样东西写软件。Linux跟随的是Unix, Windows下的开发也是 C/C++。这时候出现的C++很自然就被大家接受了,企业级的系统很自然就会迁移到这上面,C++虽然接过了C的接力棒

内核调试工具——strace

a 夏天 提交于 2020-01-16 06:07:33
简介 strace常用来跟踪进程执行时的系统调用和所接收的信号。 在Linux世界,进程不能直接访问硬件设备,当进程需要访问硬件设备(比如读取磁盘文件,接收网络数据等等)时,必须由用户态模式切换至内核态模式,通 过系统调用访问硬件设备。strace可以跟踪到一个进程产生的系统调用,包括参数,返回值,执行消耗的时间。 输出参数含义 root@ubuntu:/usr# strace cat /dev/null execve("/bin/cat", ["cat", "/dev/null"], [/* 22 vars */]) = 0 brk(0) = 0xab1000 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f29379a7000 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) ... brk(0) = 0xab1000 brk(0xad2000) = 0xad2000 fstat(1, {st_mode=S_IFCHR

40岁生日,

蓝咒 提交于 2020-01-16 05:33:28
转:http://www.ruanyifeng.com/blog/2009/06/unix_turns_40.html 1. 上 个星期, ComputerWorld 发表了一组文章,庆祝Unix操作系统诞生40周年。 虽然我以前就知道Unix的故事,但是这组文章还是令我读得津津有味。 我第一次发现,Unix这个改变了计算机工业和人类社会的操作系统,完全是一个意料之外的产物。 一个赋闲的程序员+一段意外的假期+一台被淘汰的设备,Unix就这样诞生了。 2. 那个赋闲的程序员,叫做Ken Thompson。照片上看上去很成熟,其实年龄不大,发明Unix的时候只有26岁。 1969年,他参与的研究项目Multics被贝尔实验室取消了,他顿时就无事可干了。 正好那年夏天,他的老婆带着孩子回娘家了,只留下他一个人在新泽西。反正空闲时间多得很,他就用了一个月的时间,在家里写了一个小型版的Multics。 但是,贝尔实验室没有机器可以让他测试,因为那时计算机太贵了,不可能用于一个年轻程序员的业余项目。Ken Thompson没有办法,只好在一台型号为PDP-7的小型机上测试自己的软件。这台小型机因为性能太差,所以没人去用,就被闲置在一边了。 虽然PDP-7叫小型机,其实也是庞然大物,需要一间房间才能放得下。 PDP-7在1965年上市的时候,价格是72000美元,已经属于超级便宜的计算机了

How to extract words between 2 parentheses in Unix/ Linux?

我是研究僧i 提交于 2020-01-16 04:43:09
问题 I have a SAS dataset with the list of queries as one of the variable. Below is one of the variable value: SELECT * FROM ( SELECT Table1 file2.txt file.txt QUEUES QDefinitions Parameters TRAP-Deposit-DSTran.dat.2016-08-07 FROM CS_CASE WHERE ANT_CD='FI_BASE_TENANT')t1 LEFT OUTER JOIN Table2 t2 ON t2.CASE_ID=t1.CASE_ID LEFT OUTER JOIN Table3 t3 ON t3.SERVICE_XID=t1.SERVICE_XID LEFT OUTER JOIN Table4 t4 ON t4.SERVICE_ID=t1.SERVICE_ID WHERE ( t1.CASESTATUs_CD = (NEW) OR t1.CASE_STATUS_CD = (OPEN)

Checking permission of a file using python

梦想与她 提交于 2020-01-16 04:32:07
问题 I am running a python script and very first thing to do is, it needs to check a permission of a file before it executes the whole program. I am currently using os.system("stat -c '%a' /data/lims/LI") is there a better way to do this without using os.system? my actual coding is checker = int(os.system("stat -c '%a' /data/lims/LI")) if checker != 000: print "pass" I want to check the permission of a file which should be a number... something like 755, 750, and others if it is a executable

ksh: shell script to search for a string in all files present in a directory at a regular interval

两盒软妹~` 提交于 2020-01-16 03:55:10
问题 I have a directory (output) in unix (SUN). There are two types of files created with timestamp prefix to the file name. These file are created on a regular interval of 10 minutes. e. g: 1. 20140129_170343_fail.csv (some lines are there) 2. 20140129_170343_success.csv (some lines are there) Now I have to search for a particular string in all the files present in the output directory and if the string is found in fail and success files, I have to count the number of lines present in those files