Programming :: Stuffing A Key Into Another Virtual Terminal's Stdin?
Oct 20, 2010
I want to put a keystroke into another virtual terminal's stdin.A simple 'echo p > /dev/tty7' causes a p to appear on the console of tty7 but not the app running in tty7 to respond as though a p key had been pressed. Per the instructions of a fellow in the software forum I tried using an ioctl, but that returned a permissions error, even when I made the target VT's permissions 777 (and it had the same owner).
Often in bash we read lines from stdin in a loop and implicitly discard the remaining stdin by terminating the loop. Is it possible to discard it without terminating the loop? It could lead to smaller code.
Here's an example which uses two loops and below is the same algorithm assuming unwanted stdin can be discarded
I have a small program that reads stdin from a pipe using fgets. Now fgets blocks for the first line but after that it will not block.
The code, my_echo.c - int main(int argc, char **argv) { char buf [2000] ; char* pc ; printf("hello ") ; while (1) { buf[0] = (char) 0 ; pc = fgets(buf, sizeof(buf), stdin); if (pc != NULL) printf("%s ",buf); } return 0; }
How its called * In terminal window 1: ./my_echo < my_fifo * In terminal window 2: echo "1234" > my_fifo * In terminal window 1: prints hello then 1234. * Checking with ksysguard or top shows that my_echo is consuming 40% of CPU time.
Adding a few printf's shows that the gets is not blocking and returns a null pointer. * In terminal window 2: echo "qwerty" > my_fifo * In terminal window 1 qwerty prints. I want a read function that does in fact block so my program does not tie up CPU time, read does not block.
I need to write a script which will get a number from STDIN and then with that number echo a set number of questions (its for a firewall config). Heres what I want the user to receive.
I've given the output from `df` on AWK's stdin. But what I wonder is if there's a way to get AWK to run `df` itself, produce the same output, and exit? Doesn't seem to be that simple. Here's some examples: Works for some reason, and I think only in Bash (nothing is required in the $()
[code]...
does AWK absolutely need *something* on stdin, before it begins to process the data? Can it be made to open a file or stream internally, act upon that as though it were the stdin, and exit?
I'm trying to write a shell script that do ftp and download file periodically, this script should be called by a daemon running in the background.
the shell script "script.sh" is as follows:
Code: yafc ftp://test:test@192.168.1.225:21 < commands and the "commands" files is
Code: d Root/md5* / quit
if I run script.sh it will work just fine. But when the daemon software calls the "script.sh", the script will send ftp login request to the ftp server, but will not even answer the username or anything.
I believe it is something about child process redirection, but I don't know how to deal with it.
This problem is not only with yafc, it is the same with any ftp client or any application like telnet and so.
I'm trying to write a program that will fork a series of FTP sessions. For each session, there should be separate input and output files associated with stdin and stdout/stderr. I keep reading how I should be able to do that with dup2() in the child process before the execl(), but it's not working for me. Could someone please explain what I've done wrong? The program also has a 30-second sniper alarm for testing and killing of FTPs that go dormant for too long.
The code: (ftpmon.c) #include <stdio.h> #include <stdlib.h> #include <string.h>
[code]....
The output:
$ ftpmon Connected to gila-crstest.gilacorp.com (172.16.20.8). 220 (vsFTPd 2.0.1) ftp> waitpid(): Interrupted system call
Why am I getting the ftp> prompt? If the dup2() works, shouldn't it be taking input from my script and not my terminal? In stead, it does nothing, and winds up getting killed after 30 seconds. The log file is created, but it's empty after the run.
I'm working on an application used for backup/archiving. That can be archiving contents on block devices, tapes, as well as regular files. The application stores data in hard packed low redundancy heaps with multiple indexes pointing out uniquely stored, (shared), fractions in the heap.
And the application supports taking and reverting to snapshot of total storage on several computers running different OS, as well as simply taking on archiving of single files. It uses hamming code diversity to defeat the disk rot, instead of using raid arrays which has proven to become pretty much useless when the arrays climb over some terabytes in size. It is intended to be a distributed CMS (content management system) for a diversity of platforms, with focus on secure storage/archiving. i have a unix shell tool that acts like gzip, cat, dd etc in being able to pipe data between applications.
Example:
dd if=/dev/sda bs=1b | gzip -cq > my.sda.raw.gz
the tool can handle different files in a struct array, like:
Is there a better way of getting the file name of the redirected file, (respecting the fact that there may not always exist such a thing as a file name for a redirection pipe). Should i work with inodes instead, and then take a completely different approach when porting to non-unix platforms? Why isn't there a system call like get_filename(stdin); ?
If you have any input on this, or some questions, then please don't hesitate to post in this thread. To add some offtopic to the thread - Here is a performance tip: When doing data shuffling on streams one should avoid just using some arbitrary record length, (like 512 bytes). Use stat() to get the recommended block size in stat.st_blksize and use copy buffers of that size to get optimal throughput in your programs.
I'm writing a script to execute bash commands in the PHP CLI. I would like to suppress errors from bash and write my own error message if an error occurs. So far I have this (assuming log.txt doesn't exist!):
Code:
tac log.txt 2>/dev/null
Which works as expected, tac kicks up an error but the error is suppressed, but when I use this:
Code:
tac < log.txt 2>/dev/null
I get:
Code:
bash: log.txt: No such file or directory
The tac error is suppressed but bash still gives me a dirty error.
I am a newer to debian. I want to change the color of the vitrual terminal. I have found the function " setvtrgb ",but I don't know how to mix the color , Only text green and background black...
I'm running ubuntu 9.10 on a Dell XPS M1530. Sometimes i get a _VERY_ loud beep-sound, eg when i run out of battery or, the case that has me coming here when i'm working in a virtual terminal (tty1-6) and hit backspace once too often, that is, when the command line is actually empty.Not that big of a deal you might think, but, especially when you're wearing good (read: possibly loud) headphones the experience is that god damn unpleasant that i'd like to make sure it won't happen again.Oh and well, just hitting mute (in gnome, which doesn't have a lot to do with tty1 anyways) won't do the job.
I imagine I'll have to install something, but Google has shed no light for me thus far. And just to clarify, when I say virtual terminal I mean the terminals accessed by CTRL+ALT+(F1-F6). I'm going to be doing a challenge/learning experience where I don't allow myself a graphical interface for a month. way around BASH through adaption. However, if I have to go a month without music I will go insane.
So, even if this is possible can I listen to music from the internet (....., playlist.com, etc.) or just music on my hard drive? And I'm not sure if this thread belongs in Desktop Environments or not, that section seemed to focus on graphical interface.
I cannot have any more than 47 characters on each line of my virtual terminal without everything on that line disappearing. The text is apparently still there, since commands that need more than 47 characters still work but the text stays hidden. After the text has been overlapped I can type as many characters as I like and it no longer overlaps, but my PS1 on that line and all previously overlapped text stays hidden.I'm almost certain that the problem is in my bash configuration since it happens in a terminal emulator as well as the virtual terminal.
My emacs 23 is running on Ubuntu 10.04 and I am very a emacs primer. in virtual terminals, how can I remap keys to swap the right alt key and the right ctrl key automatically every time the machine starts up? But how to swap Alt and Ctrl on the right side?
I am new to slackware, but not new to linux. I recently installed slackware 13.37, and am enjoying it very much so far. The most annoying problem I currently have is that, after starting X, I cannot switch to a virtual terminal or even end X without having a problem. For instance, from the GUI if I hit ctrl-alt-F1, instead of going to the 1st virtual terminal, the screen fades quickly to black and does not return. I have not been able to make any progress on this problem, so any input would be greatly appreciated.The only thing worth noting really is that I'm using Fluxbox as my default window manager. Other than that I haven't done a lot of modifications to the base system other than installing some basic packages, but I had this problem since booting directly after installation of the os.
When I try to go to a virtual terminal from X the writing is too dim to read. When I boot to run level 3 all is fine, then I "startx" and use the gui. If I "ctrl-alt-F3" the printing on the screen is so dim that I can't see it. Is there a setting for this somewhere that I haven't found. Before installing Slackware 13-64 I ran Zenwalk for over a year and never had this problem.
How do you increase the text size in the virtual terminal (the one you get to when you press ctrl+alt F1-6)? My monitor is pretty old and kind of small, so I need the bigger text size to really be able to use it at all. I tried to find the answer in google, but I couldn't find the answer. I found answers for suse and ubuntu and tried to use those. They said to edit part of the boot loader config file, but I couldn't find a similar line in the grub.conf file. And I don't want to play with it without knowing what I'm doing.
I recently installed Fedora 12 for some Linux testing. When I switch between virtual terminals (CTRL-f1 Ctrl-f2) I can no longer scroll back in the VT I left and came back to. Any new data created will be scrollable, but i can never get back to before the switch. I'm sure this used to work (several years ago). Was this introduced as a security feature to prevent left over data on VTs from being seen by the wrong eyes? If so, is there a way to get the old functionality back?
into /etc/profile, but it still doesn't work until I login. I'd like it to work before that, so that all messages (like those displayed on boot up) have these default settings.