unix

unix - run a command as another user [closed]

心不动则不痛 提交于 2020-01-30 04:57:09
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 7 years ago . I am a newbie to Unix. I am trying to run a shell script and command as another user. For example: I am logged in as user1 and want to execute a script as user2. I dont want the password prompt and I want it to be auto-entered. I am aware of the public key authentication but I am trying to find if there is

TCP Connection Seems to Receive Incomplete Data

北慕城南 提交于 2020-01-29 19:45:03
问题 I've setup a simple TCP file transfer. Everything appears to work OK, except for the received file size is sporadically a smaller size than the file that was sent. There doesn't appear to be any pattern to the size of the received file. (in the code below, note that the typical client/server rolls are reversed) My client code is like: #define kMaxBacklog (5) // fill out the sockadd_in for the server struct sockaddr_in servAdddress; //memcpy() to fill in the sockaddr //setup the socket int

Parse string with bash and extract number

拥有回忆 提交于 2020-01-29 06:15:05
问题 I've got supervisor's status output, looking like this. frontend RUNNING pid 16652, uptime 2:11:17 nginx RUNNING pid 16651, uptime 2:11:17 redis RUNNING pid 16607, uptime 2:11:32 I need to extract nginx's PID. I've done it via grep -P command, but on remote machine grep is build without perl regular expression support. Looks like sed or awk is exactly what I need, but I don't familiar with them. Please help me to find a way how to do it, thanks in advance. 回答1: sed 's/.*pid \([0-9]*\).*/\1/'

进程间通信小结

瘦欲@ 提交于 2020-01-29 02:04:28
进程间通信: 1、进程间的数据共享: 管道、 消息队列、 共享内存、 Unix域套接字 易用性: 消息队列 > Unix域套接字 > 管道 > 共享内存(经常与信号量一起用) 效 率: 共享内存 > Unix域套接字 > 管道 > 消息队列 常 用: 共享内存、Unix域套接字 2、异步通信 信号 3、同步与互斥(做资源保护) 信号量 来源: https://www.cnblogs.com/y4247464/p/12239464.html

UNIX SHELL基础知识总结(一)

让人想犯罪 __ 提交于 2020-01-28 17:12:47
1. Unix常目录结构与作用: 2. 基本命令 : $echo $date $who $who am i 3. 创建文件的几种方式 : A. touch FileName 创建空文件 B. > FileName 创建空文件 C. vi FileName 创建空文件并开始编辑其中内容 D. cat /dev/null > FileName 创建空文件 4. 文件操作: $rm:删除文件;(rm -rf FilePath:强制删除FilePath及其下的所有内容;r:向下递归;f:强制删除,不做任何提示) $cp:文件复制; $mv:文件重命名; $cat:查看文件内容; $ls[list]:(-l 显示文件详细描述信息)查看当前目录中的文件; $wc:(-l:行数;-c:字符数;-w:单词数)统计文件中的单词数量; $ln:链接文件; $sort:排序; $file:查看文件类型; 5. 文件夹操作: $.:当前目录; $mkdir(Make Directory):创建目录; $cd(Change Directory):切换目录; $pwd(Print Working Directory):显示宿主目录; $rmdir(Remove Directory)删除目录; $mv:文件移动 6. 文件基本类型: 以‘_’开头为普通文件; 以‘b’开头为块设备(Block Device);

How to transfer a file between two remote servers using scp from a third, local machine?

*爱你&永不变心* 提交于 2020-01-28 16:37:36
问题 I'm trying to copy a file from one remote server to another remote server from my local machine. Here's what I'm trying to do localA $ scp userB@remoteB:/path/to/file userC@remoteC:/path The problem is that I need to pass two passwords for both userB and userC on the remote machines. According to Garron the above should work, but I got permission denied. Permission denied (gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive). lost connection Any suggestions? 回答1: This questions

How to attach a file using mail command on Linux? [duplicate]

对着背影说爱祢 提交于 2020-01-27 03:22:07
问题 This question already has answers here : How do I send a file as an email attachment using Linux command line? (26 answers) Closed 2 years ago . I'm on a server running a Linux shell. I need to mail a simple file to a recipient. How to do this, prefereably using only the mail command? UPDATE : got a good solution, using mutt instead: $ echo | mutt -a syslogs.tar.gz admin@domain.org 回答1: Example using uuencode: uuencode surfing.jpeg surfing.jpeg | mail sylvia@home.com and reference article:

How to attach a file using mail command on Linux? [duplicate]

↘锁芯ラ 提交于 2020-01-27 03:22:06
问题 This question already has answers here : How do I send a file as an email attachment using Linux command line? (26 answers) Closed 2 years ago . I'm on a server running a Linux shell. I need to mail a simple file to a recipient. How to do this, prefereably using only the mail command? UPDATE : got a good solution, using mutt instead: $ echo | mutt -a syslogs.tar.gz admin@domain.org 回答1: Example using uuencode: uuencode surfing.jpeg surfing.jpeg | mail sylvia@home.com and reference article:

Using grep and sed to find and replace a string

一笑奈何 提交于 2020-01-26 21:57:20
问题 I am using the following to search a directory recursively for specific string and replace it with another: grep -rl oldstr path | xargs sed -i 's/oldstr/newstr/g' This works okay. The only problem is that if the string doesn't exist then sed fails because it doesn't get any arguments. This is a problem for me since i'm running this automatically with ANT and the build fails since sed fails. Is there a way to make it fail-proof in case the string is not found? I'm interested in a one line

Using grep and sed to find and replace a string

走远了吗. 提交于 2020-01-26 21:54:12
问题 I am using the following to search a directory recursively for specific string and replace it with another: grep -rl oldstr path | xargs sed -i 's/oldstr/newstr/g' This works okay. The only problem is that if the string doesn't exist then sed fails because it doesn't get any arguments. This is a problem for me since i'm running this automatically with ANT and the build fails since sed fails. Is there a way to make it fail-proof in case the string is not found? I'm interested in a one line