কিভাবে পটভূমিতে শেল স্ক্রিপ্ট চালানো যায়?


উত্তর:


93

আপনি যা চাইছেন তার উপর নির্ভর করে কমান্ডের শেষে কেবল একটি & যুক্ত করুন

script.sh &
command &

আপনি যদি এটি কোনও টার্মিনালে চালাচ্ছেন এবং আপনি টার্মিনালটি বন্ধ করতে চান তবে নোহপ ব্যবহার করুন বা অস্বীকার করুন

nohup

nohup script.sh &

ত্যাজ্য করা

script &
disown

আপনি যদি পরে তা না করেন তবে আপনার প্রশ্নে আরও সুনির্দিষ্ট হন।


আপনাকে সর্বাধিক স্বাগতম
— প্যান্থার

যদি আমি উদাহরণস্বরূপ 2 টি স্ক্রিপ্ট চালাতে চাই এবং তারপরে আমি htopসিপিইউ ব্যবহার দেখতে চালাতে চাই তবে সমস্যাটি হচ্ছে 1 ম স্ক্রিপ্টটি কনসোলের জন্য আউটপুট তৈরি করা শুরু করে এবং এটি অন্যান্য ক্রিয়াকলাপগুলি রোধ করে (দ্বিতীয় স্ক্রিপ্ট চালান, চালান htop))
— mrgloom

যদি স্ক্রিপ্টের মুদ্রণ বিবৃতি থাকে তবে সেগুলি কি আমার টার্মিনালে প্রদর্শিত হবে?
— চার্লি পার্কার

2

আপনি কেবল স্ক্রিনটি স্যুইচ করতে পারেন এবং আপনার স্ক্রিপ্টটি ২ য় স্ক্রিনে চালাতে পারেন। স্ক্রিপ্ট যখন ২ য় তারিখে শুরু হয়, তখন ১ ম এ ফিরে যান এবং যা খুশি তা করুন। ২ য় পর্দা অতিরিক্ত "টার্মিনাল উইন্ডো" হিসাবে পটভূমিতে থাকবে। এবং 1 ম স্ক্রিনে মৌমাছির সময় আপনি যখন আপনার এসএসএস সংযোগটি বন্ধ করেন তখনও এটি প্রক্রিয়াজাতকরণ বন্ধ করবে না।

screen --help
Use: screen [-opts] [cmd [args]]
 or: screen -r [host.tty]

Options:
-4            Resolve hostnames only to IPv4 addresses.
-6            Resolve hostnames only to IPv6 addresses.
-a            Force all capabilities into each window's termcap.
-A -[r|R]     Adapt all windows to the new display width & height.
-c file       Read configuration file instead of '.screenrc'.
-d (-r)       Detach the elsewhere running screen (and reattach here).
-dmS name     Start as daemon: Screen session in detached mode.
-D (-r)       Detach and logout remote (and reattach here).
-D -RR        Do whatever is needed to get a screen session.
-e xy         Change command characters.
-f            Flow control on, -fn = off, -fa = auto.
-h lines      Set the size of the scrollback history buffer.
-i            Interrupt output sooner when flow control is on.
-l            Login mode on (update /var/run/utmp), -ln = off.
-ls [match]   or -list. Do nothing, just list our SockDir [on possible matches].
-L            Turn on output logging.
-m            ignore $STY variable, do create a new screen session.
-O            Choose optimal output rather than exact vt100 emulation.
-p window     Preselect the named window if it exists.
-q            Quiet startup. Exits with non-zero return code if unsuccessful.
-r [session]  Reattach to a detached screen process.
-R            Reattach if possible, otherwise start a new session.
-s shell      Shell to execute rather than $SHELL.
-S sockname   Name this session <pid>.sockname instead of <pid>.<tty>.<host>.
-t title      Set title. (window's name).
-T term       Use term as $TERM for windows, rather than "screen".
-U            Tell screen to use UTF-8 encoding.
-v            Print "Screen version 4.01.00devel (GNU) 2-May-06".
-wipe [match] Do nothing, just clean up SockDir [on possible matches].
-x            Attach to a not detached screen. (Multi display mode).
-X            Execute <cmd> as a screen command in the specified session.

ctrl+ a, cআপনার সক্রিয় স্ক্রিন সেশনে একটি নতুন "উইন্ডো" তৈরি করবে। আপনার সাথে একাধিক উইণ্ডো মধ্যে স্যুইচ করতে পারেন (যেমন Ansgar নির্দেশিত) ctrl+ + a, nপরবর্তী উইন্ডোতে জন্য, এবং ctrl+ + a, pপূর্ববর্তী উইন্ডোতে জন্য।

ctrl+ a, "আপনাকে আপনার সমস্ত খোলা উইন্ডোজের একটি তালিকা দেবে।

আরও: https://superuser.com


1

আপনি যদি টার্মিনালটি বন্ধ করার পরে স্ক্রিপ্টটি থাকতে চান তবে অন্য একটি বিকল্প ব্যবহার করা উচিত setsid:

setsid script.sh

মধ্যে পার্থক্য সম্পর্কে আরো তথ্যের জন্য nohup, disown, &এবং setsid: nohup মধ্যে পার্থক্য, অস্বীকার এবং &

আমাদের সাইট ব্যবহার করে, আপনি স্বীকার করেছেন যে আপনি আমাদের কুকি নীতি এবং গোপনীয়তা নীতিটি পড়েছেন এবং বুঝতে পেরেছেন ।
Licensed under cc by-sa 3.0 with attribution required.