where to look for previously executed commands - linux

I want to understand how up/down arrow keys help to navigate through previously executed commands. which memory it access to get last executed command?
Currently i am working on unix similar Machine "Stratus VOS" where i can see only last 1 executed command and that too with F10 key.
I want to create a script/tool which can help to me to get at least last 10-15 executed commands to save my time during development work.
what i noticed so far on Stratus Machine:
1: fc command doesn't work.
2. no HISTFILE is maintained. no history command works.
what i thought to implement:
find which memory in system holds last executed command, access that memory(whenever Enter key is pressed ) and keep writing in file.
am i on right track? is there any better solution for this?

I would suggest that while possible your solution is possibly overcomplex and likely to be difficult and possibly unreliable. I would instead consider using the Stratus VOS GNU tools package which includes a full GNU Bash shell with all the features you expect including the command history support.
A little documentation on GNU tools for Stratus VOS appears to be available here though I would suggest contacting your vendor for more information or support.

Related

Why isn't this command running properly?

So I'm making a better command-line frontend for APT and I'm putting on some finishing touches and when the code below runs.
Command::new("unbuffer")
.arg("apt")
.arg("list")
.arg("|")
.arg("less")
.arg("-r")
.status()
.expect("Something went wrong.");
it spits out:
E: Command line option 'r' [from -r] is not understood in combination with the other options.
but when I just run unbuffer apt list | less -r manually in my terminal it works perfectly. How do I get it to run properly when calling it in Rust?
Spawning a process via Command uses the system's native functionality to create a process. This is a low level feature and has little to do with your shell/terminal that you are used to. In particular, your shell (e.g. bash or zsh, running inside of your terminal) offers a lot more features. For example, piping via | is such a feature. Command does not support these features as the low level system's API doesn't.
Luckily, the low level interface offers other means of achieving a lot of stuff. Piping for example is mostly just redirecting the standard inputs and outputs. You can do that with Command::{stdin, stdout, sterr}. Please see this part of the documentation for more information.
There are a few very similar questions, which are not similar enough to warrent closing this as a dupe though:
Execute a shell command
Why does the compgen command work in the Linux terminal but not with process::Command?: mentions shell built-in commands that do not work with Command.
Executing find using std::process::Command on cygwin does not work

Creating a time serie with top and nodeJS

I would like to create a time series and inject it into InfluxDb for a demo. I thought about using the top command (top -pid 1393 -stats cpu), and use the CPU value. And then use NodeJS to extract the data and inject it into an InfluxDB. However, there are a couple of but...:
1- The top command has a display section: can it be removed?
2- In Node, I would call (repeatedly) "top -pid 1393 -stats cpu -l 1" with the "-l 1" option to only get a singe sample. I feel it is a misuse of the fact that top generates data at given intervals (basically, I recreate in Node what top does automatically)
Is there a better way to do this - in the ideal world, I would launch top in node and "pipe" the output stream to a variable in an async way (to execute the insertion into InfluxDB).
Thanks for any hints you may have.
Christian
In actual fact, there is a node module for this: see npm usage.
Note that you may have an issue when installing the usage module, generated by node-gyp rebuild (usage requires this module, which requires XCode in Mac platform - see https://github.com/nodejs/node-gyp). To solve this, look here: xcode-select active developer directory error)
Thanks - C
To monitor the process' resource consuming metrics (correct me if I took your intentions wrong), you don't need your NodeJS stuff at all.
All you need is running Telegraf agent, with this plugin configured, on the machine(s) you're targeting.
Point the output plugin to your Influx - and that's it.
As mention in other comments, there are specific tools for that task. Anyway, if you still want to do it programmatically, I would suggest to either:
run top in non-interactive mode, as explained here: https://unix.stackexchange.com/questions/255100/get-top-output-for-non-interactive-shell
read directly the information that you need from /proc/<pid of your process>/<file of interest>

Run many commands in Linux Mint quickly

I'm very much learning my way around the command line. I have several commands I want to occasionally run, mostly on a restart, but at other misc times as well. Can I have some kind of file which can contain these commands and execute the file from the command line so that they are all ran at once? Would this be the general correct approach? And if so, how would I actually achieve this? Thanks for your guidance.
What you want is an "init script".
http://www.tldp.org/HOWTO/HighQuality-Apps-HOWTO/boot.html
This enables you to define the behaviour of several services, and then determine in what run level you want them to start / stop at (EG: run level 6 for restart).
http://www.tldp.org/LDP/sag/html/run-levels-intro.html
You might also benefit from some "alias"'es in your shell (assuming you are using BASH).
http://tldp.org/LDP/abs/html/aliases.html

how to open system date, sound, display properties in linux?

I know there are APIs in windows like "desk.cpl", "timedate.cpl" , "sndvol".
I use these in system command to open from a SLOT.
I want to know about these alternatives for Linux.
Please help me is there any command to open these 3 from terminal I only want to show this.
Execute following command in terminal
gnome-control-center display
gnome-control-center datetime
gnome-control-center sound
As a Linux user I do not know what those MS-Windows "things" you mention actually do and you appear to take that for granted. So I have to guess here:
to get the current system time on shell level you can use date. See the man page for details: man date.
for the current volume setting, not easy to answer, since Linux is a very modular system. Most likely you could ask DBus about that, but this really depends on what desktop environment and what sound system you use. You might try amixer get PCM|tail -n1|sed -r 's/.*\[(.*)%\].*/\1/', but as said that really depends...
No idea what "desk.cpl" does, so I cannot say anything about this "thing".

What is xsession-errors?

So I was looking into why a program was getting rid of my background, and the author of the program said to post .xsession-errors and many people did. Then my next question was: What is .xsession-errors? A google search reveals many results but nothing explaining what it is.
What I know so far:
It's some kind of error log. I can't figure out what it's related too (ubuntu itself? programs?)
I have one and it seems like all Ubuntu systems have it, though I cannot verify.
Linux graphical interfaces (such as GNOME) provide a way to run applications by clicking on icons instead of running them manually on the command-line. However, by doing so, output from the command-line is lost - especially the error output (STDERR).
To deal with this, some display managers (such as GDM) pipe the error output to ~/.xsession-errors, which can then be used for debugging purposes. Note that since all applications launched this way dump to the same log, it can get quite large and difficult to find specific messages.
Update: Per the documentation:
The ~/.xsession-errors X session log file has been deprecated and is
no longer used.
It has been replaced by the systemd journal (journalctl command).
It's the error log produced by your X windows system (which the Ubuntu GUI is built on top of).
Basically it's quite a low level error log for X11.

Resources