Check file exists on the appvm from dom0 viw qvm-run or other variants?

46 views
Skip to first unread message

Eva Star

unread,
Jul 4, 2016, 5:04:20 PM7/4/16
to qubes-devel
How to check that file exists on AppVm from dom0 bash script? 

Or simple get the exit code of the remote process? 

status=$(qvm-run --pass-io $appvm "test -r $file; echo $?" > file_with_exit_code_always_with_null_why

status=$(qvm-run --pass-io $appvm "cat $file" > dom0file
If $file is not exists how to get notify about it on bash script?

thanks

Ivan

unread,
Jul 5, 2016, 1:34:25 AM7/5/16
to qubes...@googlegroups.com


On 07/05/2016 12:04 AM, Eva Star wrote:
> How to check that file exists on AppVm from dom0 bash script?
>
> Or simple get the exit code of the remote process?
>
> status=$(qvm-run --pass-io $appvm "test -r $file; echo $?" >
> file_with_exit_code_always_with_null_why

no need to echo $?, the exit code is passed to dom0 too. Eg.:

# qvm-run --pass-io $appvm "test -e /bin/ls"
# echo $?
0

# qvm-run --pass-io $appvm "test -e /bin/blah"
# echo $?
1


>
> status=$(qvm-run --pass-io $appvm "cat $file" > dom0file
> If $file is not exists how to get notify about it on bash script?

if ! $(qvm-run --pass-io $appvm "test -e $file"); then
your_commands_here; fi

but you'll also catch qvm-run errors (eg. $appvm not running). A
workaround would be to choose a custom exit value, like so:

qvm-run --pass-io $appvm "test -e $file || exit 199"
if [ $? -eq 199 ]; then
your_commands_here
fi




> thanks
>

Eva Star

unread,
Jul 5, 2016, 12:01:01 PM7/5/16
to qubes-devel, iv...@c3i.bg
Unfortunately, this does not work at bash script, only when you execute echo $? on console its give you right results. When you execute this command with sh script then it always return 0. I think the problem that on bash script its return qvm-run echo code instead of remote code.

Marek Marczykowski-Górecki

unread,
Jul 5, 2016, 2:09:04 PM7/5/16
to Eva Star, qubes-devel, iv...@c3i.bg
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Yes, when you include 'echo' (or anything else after that 'test') inside
qvm-run argument, it will shadow exit code. If executing just 'test -r
somefile' through qvm-run should just work.


- --
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBCAAGBQJXe/e4AAoJENuP0xzK19csMrkH/jJLw32lRdtrCdWryldAi9Id
jhsCjxIUjkXj733NOGhFVoxDs6OhJeL9oqc4SFtRDjuahBfAUi4x4+oCu7vG2+r2
sFD9ahNAoCp6I7eZsa25eJzaqWFGiDdvY0Q9HPY9AqyDkZ5GO3v+fsRplM4TVk2I
HC7+s0RnjI5FtiJUHt5SDWmLkq8b1m8e+wXt+3LQPBEgATnBx6+gScuXHHdkBXah
LYaoAUGAEl8BefkqvMb5X8PcElSsZq63dkkPPFr40DSTI6FGNClhBQr833wnxOVI
uKXA/hZmrMeFWq+orA/prMnrVgKE6+7K3Cg5WGfujYTKm422q7rvWTDYjnczarg=
=mAYL
-----END PGP SIGNATURE-----
Reply all
Reply to author
Forward
0 new messages