I don't want my code to be repeated several times. Grub4Dos has options for solving this problem, such as functions?
Grub4Dos don't have functions in the usual sense (as in Grub2) but you can use configfile command as functions.
Example:
menu.lst:
set ldpartnew=(hd0,0)/boot/grub4dos/load_partnew.lst
title archlinux-2021.02.01-x86_64
set ISO=(hd0,1)/ISO/archlinux-2021.02.01-x86_64.iso
configfile %ldpartnew%
load_partnew.lst:
partnew (hd0,3) 0 0 0
partnew (hd0,3) 0 0 0
partnew (hd0,3) 0 0 0
ls %ISO% && partnew (hd0,3) 0x00 %ISO%
map %ISO% (hd0,3)
map --hook
root (hd0,3)
chainloader (hd0,3)
Casper:
menu.lst:
set ldcasper=(hd0,0)/boot/grub4dos/load_casper.lst
title ubuntu-20.04.2.0-desktop-amd64
set ISO=(hd0,1)/ISO/ubuntu-20.04.2.0-desktop-amd64.iso
# ISOwohd is path to ISO without (hdX,X)
set ISOwohd=/ISO/ubuntu-20.04.2.0-desktop-amd64.iso
# initrdX is file extension of initrd file
configfile %ldcasper%
load_casper.lst:
map %ISO% (0xff)
echo -e \r\n
map --hook
root (0xff)
kernel (0xff)/casper/vmlinuz%vmlinuzX% file=/cdrom/preseed/ubuntu.seed boot=casper persistent iso-scan/filename=%ISOwohd% splash
initrd (0xff)/casper/initrd%initrdX%
Tested on grub4dos-0.4.6a-2021-01-27.
The problems I encountered in the process of using this method:
A variable name that is too long causes an error.
Since it is impossible to pass parameters to such functions in the usual way, it is necessary to declare additional variables of the type ISO, ISOwohd and initrdX.
Related
I'm trying to configure rsyslog to output in RFC5424 format. This means that the PROCID must be output in the syslog header. If there's no header, it should output a single dash (-) in its place. However, some of the events output have it just blank, and some have an actual value.
This is rsyslogd 5.8.10 running on Amazon Linux.
Here are the config lines:
$template CustomFormat,"<%PRI%>1 %timegenerated:1:23:date-rfc3339%-00:00 %HOSTNAME% %app-name% b%procid%b %msgid% %STRUCTURED-DATA%%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"
$ActionFileDefaultTemplate CustomFormat
Note that I put a "b" on each side of %procid% to make it more visible (this part is not RFC5424-compliant). Here are two lines of sample output.
<87>1 2019-06-19T20:03:01.929-00:00 ip-10-90-0-15 crond b29408b - - pam_unix(crond:account): expired password for user root (password aged)
<85>1 2019-06-19T20:17:18.150-00:00 ip-10-90-0-15 sudo bb - - ssm-user : TTY=pts/0 ; PWD=/ ; USER=root ; COMMAND=/bin/vi /etc/rsyslog.conf
The first line is correct, but the second example should have "b-b" instead of "bb". What should I do to make the blank %procid% show up as a dash? It works fine for the %msgid% and %STRUCTURED-DATA%.
Is there a better way to get RFC5424 output? (I have to use -00:00 instead of Z.)
There may be a better way, but one thing you can try is to use a Rainer script variable in the template instead of the property, and set this variable to "-" if the procid is empty. For example,
$template CustomFormat,"<%PRI%>1 ... b%$.myprocid%b ..."
$ActionFileDefaultTemplate CustomFormat
if ($procid == "") then {
set $.myprocid = "-";
} else {
set $.myprocid = $procid;
}
*.* ./outputfile
Just make sure the if statement is before any action statements. Note, you cannot change the procid property itself with set.
I am using flexcan driver on an embedded linux and I have C program controling can messages. In my C program I need to check the state of the can bus e.g. buss-off or error-active. I can use linux command like
ip -details -statistics link show can0 with following result:
2: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UP mode DEFAULT group default qlen 10
link/can promiscuity 0
can state *ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 100
bitrate 250000 sample-point 0.866
tq 266 prop-seg 6 phase-seg1 6 phase-seg2 2 sjw 1
flexcan: tseg1 4..16 tseg2 2..8 sjw 1..4 brp 1..256 brp-inc 1
clock 30000000
re-started bus-errors arbit-lost error-warn error-pass bus-off
31594 0 0 7686 25577 33258
RX: bytes packets errors dropped overrun mcast
5784560 723230 0 1 0 0
TX: bytes packets errors dropped carrier collsns
157896 19742 0 33269 0 0
How can I get that can state ERROR-ACTIVE in my C program? Also I can see in the flex can driver there are some registers that can be used to see the state but I don't know how to include these values in my program also. registers like FLEXCAN_ESR_BOFF_INT contains the values that I need.
You can setup your socket to return CAN errors as messages.
As described in Network Problem Notifications the CAN interface driver
can generate so called Error Message Frames that can optionally be
passed to the user application in the same way as other CAN frames.
The possible errors are divided into different error classes that may
be filtered using the appropriate error mask. To register for every
possible error condition CAN_ERR_MASK can be used as value for the
error mask. The values for the error mask are defined in
linux/can/error.h
can_err_mask_t err_mask = ( CAN_ERR_TX_TIMEOUT | CAN_ERR_BUSOFF );
setsockopt(s, SOL_CAN_RAW, CAN_RAW_ERR_FILTER,
&err_mask, sizeof(err_mask));
See kernel documentation for more information.
Update
Take a look at libsocketcan and the routine can_get_state.
What does this instructions mean in flex (lex) :
#define yywrap() 1
and this [ \t]+$
i find it in the code below:
(%%
[ \t]+ putchar('_');
[ \t]+%
%%
input "hello world"
output "hello_world"
)
According to The Lex & Yacc Page :
When the scanner receives an end-of-file indication from YY_INPUT, it then checks the yywrap() function. If yywrap() returns false (zero), then it is assumed that the function has gone ahead and set up yyin to point to another input file, and scanning continues. If it returns true (non-zero), then the scanner terminates, returning 0 to its caller. Note that in either case, the start condition remains unchanged; it does not revert to INITIAL.
The #define is used to simplify building the program (so that no -ll linkage option is needed).
Further reading:
What are lex and yacc?
Routines to reprocess input
6. How do Lex and YACC work internally (Lex and YACC primer/HOWTO)
let's say i have an executable file stored in c:\my directory\my file.exe that i would like to initiate near the beginning of my R script, and then terminate near the end of my R script. what are some clean ways do this on a windows platform?
i am aware of R commands like shell and shell.exec, but it's not clear to me that these will allow a clean capture of the process id to then use something like the pskill function. it's also not clear if it makes more sense to run this executable through some sort of pipe conection - or how that pipe would work. this particular executable should be included in my windows PATH as a system variable, so it's conceivable that the system function might be of value here as well.
additional clarification: capturing the process id might be important, because (at least for me) this will be used on a database server's executable -- if multiple database servers are currently running on the same machine, the process shouldn't kill all of them - just the one initialized at the start of the R script.
for extra credit: let's say c:\my directory\my file.exe should be called by actually executing another file - c:\my directory\another file.bat - but it's my file.exe that needs to be killed at the end of the R script.
drawing on the other two answers received, this technique seems like a reasonable way to accomplish the stated goal..
# specify executable file
exe.file <- "C:\\Users\\AnthonyD\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"
# capture the result of a `tasklist` system call
before.win.tasklist <- system2( 'tasklist' , stdout = TRUE )
# store all pids before running the process
before.pids <- substr( before.win.tasklist[ -(1:3) ] , 27 , 35 )
# run the process
shell.exec( exe.file )
# capture the result of a `tasklist` system call
after.win.tasklist <- system2( 'tasklist' , stdout = TRUE )
# store all tasks after running the process
after.tasks <- substr( after.win.tasklist[ -(1:3) ] , 1 , 25 )
# store all pids after running the process
after.pids <- substr( after.win.tasklist[ -(1:3) ] , 27 , 35 )
# store the number in the task list containing the PIDs you've just initiated
initiated.pid.positions <- which( !( after.pids %in% before.pids ) )
# remove whitespace
after.tasks <- gsub( " " , "" , after.tasks )
# find the pid position that matches the executable file name
correct.pid.position <-
intersect(
which( after.tasks %in% basename( exe.file ) ) ,
initiated.pid.positions
)
# remove whitespace
correct.pid <- gsub( " " , "" , after.pids[ correct.pid.position ] )
# write the taskkill command line
taskkill.cmd <- paste( "taskkill" , "/PID" , correct.pid )
# wait thirty seconds (so the program fully loads)
Sys.sleep( 30 )
# kill the same process that was loaded
system( taskkill.cmd )
You could use system function:
system("Taskkill /IM myfile.exe /F")
edit: This worked in my computer with Windows 7 (tested with killing skype.exe).
In the past, I used psKill. It is really powerful and maybe dangerous. You kill multi-procees even ina remote computer. I think you konw we must be extremely careful when we want to kill brutally process.
Download the tool , unzip and copy in a known path.
First time you launch is asking for liscence..You launch it from the cmd once and you agree.
Then you use somthing like this
process_name <- 'your_process_name'
system(paste(path_to_pskil,'pskill ',process_name,sep=''),intern=T)
For example to kill all chrome instances, you do this
system('c:/temp/pskill chrome',intern=T) !!
EDIT
Assuming you have multi process with the same name. You can use pslist to list all process with this name. Find the id of the process you want to kill according to its elapsed time, then call pskill by id.
For example here I want to kill , the last launched chrome process
my.process <- system('c:/temp/pslist chrome ',intern=T)[-c(1:8)]
my.process
[1] "chrome 3852 8 38 1052 141008 0:01:58.108 1:43:11.547"
[2] "chrome 5428 8 11 202 220392 0:02:08.092 1:43:11.359"
[3] "chrome 6228 8 9 146 73692 0:01:58.467 1:43:00.091"
[4] "chrome 6312 6 9 130 45420 0:00:08.704 1:17:30.153"
[5] "chrome 360 6 9 127 29252 0:00:01.263 0:57:01.084"
[6] "chrome 5032 6 9 126 29596 0:00:00.717 0:31:39.875"
[7] "chrome 2572 8 9 120 23816 0:00:00.452 0:19:10.307"
## ids are orderd according to the elpased time
## I use tail to get the last one
## some regular expression to get the id from the string
## mine is ugly but I am sure you can do better.
id <- substr(gsub("([^[:digit:]]*)", "", tail(my.process,1)),1,4)
system(paste('c:/temp/pskill ', id) ,intern=T)
I have tried to see if I could get Brendan Gregg's sshkeysnoop.d to work on Mac OS X, but am having trouble. Is it possible to get this working? If so, how?
The error I am getting is:
dtrace: failed to compile script ./sshkeysnoop.d: line 40: probe description syscall::exec:return does not match any probes
Is it possible to do any other kind of key logging on Mac OS X using DTrace?
A couple things you can do to adapt scripts like this. First, you can ask dtrace what probe points it has:
$ sudo dtrace -l -f 'syscall::exec*'
ID PROVIDER MODULE FUNCTION NAME
18442 syscall execve entry
18443 syscall execve return
Second, you can trace all syscalls on a single process to see what's going on.
$ sudo dtruss ssh somewhere 2>dtrussout
Password: (type something here)
If you look through dtrussout you can see
read_nocancel(0x5, "a\0", 0x1) = 1 0
read_nocancel(0x5, "s\0", 0x1) = 1 0
read_nocancel(0x5, "d\0", 0x1) = 1 0
read_nocancel(0x5, "f\0", 0x1) = 1 0
read_nocancel(0x5, "\n\0", 0x1) = 1 0
With that knowledge, it's pretty easy to adapt the script.
$ diff sshkeysnoop.d{.orig,}
40c40
< syscall::exec:return, syscall::exece:return
---
> syscall::execve:return
51c51
< syscall::open:entry, syscall::open64:entry
---
> syscall::open:entry
58c58
< syscall::open:return, syscall::open64:return
---
> syscall::open:return
68c68
< syscall::read:entry
---
> syscall::read_nocancel:entry
75c75
< syscall::read:return
---
> syscall::read_nocancel:return
OS X does not have a syscall::exec DTrace probe. It does have a syscall::execve though. Similarly it doesn't have syscall::open64, which is also used in this script. However, even with replacing exec with execve and removing open64, the script doesn't function correctly.
Also make sure you are loading with the all option
kldload dtraceall
and not just
kldload dtrace
Or the syscalls are not going to get loaded.